[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-25。"],[],[],null,["# Dates and times\n\n| **Note:** This page describes how to work with date and time data types in Looker Studio. To learn how to change the way those dates and times are displayed in a report, see [Format fields in reports](/looker/docs/studio/format-fields-in-reports).\n\nYou can use Looker Studio to visualize and compare dates and times in charts and graphs, and let users adjust the report's date range. You can also use date functions in calculated fields to manipulate and transform date and time data.\n\nDate and time data types\n------------------------\n\nLooker Studio supports the following calendar date and time data types:\n\n### Date \\& Time (compatibility mode)\n\nDate and time dimensions in data sources created before September 15, 2020 use a Date \\& Time (compatibility mode) data type. Compatibility mode dates include the format or an example in the name.\n\nCompatibility mode dates have both a [**Format Type**](/looker/docs/studio/format-fields-in-reports) and a **Granularity** option when editing the field in charts. To adjust a chart's date grouping, use the **Granularity** option.\n\n#### Upgrade a compatibility mode date field\n\nCompatibility mode dates continue to work in your existing components and calculated fields. However, you can't use compatibility mode dates with all of the available date and time functions. To use those functions, you can upgrade your date fields to new Date or Date \\& Time data types.\n| **Warning:** When you upgrade a compatibility mode date to a new Date or Date \\& Time type:\n|\n| - You can use the upgraded field with functions such as `DATETIME_ADD`, `DATETIME_DIFF`, `EXTRACT`, and more.\n| - Calculated fields and filters that expect a specific data format might fail, due to the new data type's formatting. You can fix any broken components by adjusting the formulas or filters to use the upgraded field's new format.\n| - You can't change a Date or Date \\& Time field to compatibility mode. The compatibility mode type is turned off for upgraded fields.\n| - If you decide you want to undo the change, use [version history](/looker/docs/studio/see-whats-changed-in-reports-and-data-sources) in the data source to restore an earlier version.\n\n**To upgrade:**\n\n1. [Sign into Looker Studio](https://lookerstudio.google.com).\n2. [Edit your data source](/looker/docs/studio/edit-a-data-source).\n3. Locate the compatibility mode date field you want to convert.\n4. Click the field's **Type** menu, then select **Date \\& Time**.\n5. Select the desired date type.\n6. In the dialog box that appears, click **UPGRADE**.\n\n\u003e Because upgrading might impact your reports, you must upgrade date and time fields individually. Reconnecting your data source won't upgrade the fields.\n\u003e\n\u003e The following connectors don't support the new Date and Date \\& Time data types, so you can't upgrade to or create those types in data sources using these connectors:\n\u003e\n\u003e - Cloud Spanner\n\u003e - YouTube Analytics\n\u003e - BigQuery using Legacy SQL\n\nUse dates and times in charts\n-----------------------------\n\nYou can group (aggregate) the data in your charts by different levels of date granularity according to the date field's data type. For example, adding a Date field to your chart groups the data by year, month, and day. To group the data by month, change type to Month, or use a Month field from your data source.\n\n1. Chart showing Metric by full date.\n2. Chart showing Metric by month.\n\nChange a field's data type\n--------------------------\n\nYou can change a field's data type in a chart or from the data source itself:\n\n- If you change a field's data type from the data source, the new data type is applied to the field everywhere the field is used. This may limit how you can use that field in charts.\n- If you change a field's data type from a chart, the new data type is applied to the field only in that one chart.\n\nTo change a field's data source everywhere the field is used, select the field's **Type** menu in the data source:\n\nTo change a field's data source in a single chart only, click the field's **Edit** icon in the **SETUP** tab of a report:\n\n| **Best practice:** Always have a full Date or Date \\& Time field in your data source. Use that field in your charts and adjust the field's type in the chart:\n|\n| 1. [Edit your report](/looker/docs/studio/edit-a-report)\n| 2. Select the chart.\n| 3. Place your cursor over the date field, then click the **Edit** icon .\n| 4. Select the new field type.\n\nUse dates and times in calculated fields\n----------------------------------------\n\nYou can use functions in calculated fields to create new columns of date and time data in your data source or directly in components on the report.\n\nFor example, you can construct a complete date from separate numeric day, month, and year fields using the `DATE` function. You can extract date and time parts from a date with functions like `YEAR`, `DAY`, and `HOUR`. You can calculate the difference between 2 dates using `DATETIME_DIFF`, or add a certain number of time parts using `DATETIME_ADD`.\n\n[Learn more about date and time functions](/looker/docs/studio/currentdate).\n\n### Date and Date \\& Time literals\n\nTo use literal date and time values in a calculated field, you can precede the value with the appropriate marker:\n\n### Examples:\n\nCalculate the difference between a date from data and a specific fixed date:\n\n`DATETIME_DIFF(date_field, DATE \"2008-12-25\", DAY)`\n\nFormat a date as text:\n\n`FORMAT_DATETIME(\"%x\", DATE \"2008-12-25\")`\n\nRelated resources\n-----------------\n\n- [Set report date ranges](/looker/docs/studio/set-report-date-ranges)\n- [Date range control](/looker/docs/studio/date-range-control)\n- [About calculated fields](/looker/docs/studio/about-calculated-fields)\n- [Looker Studiofunction list](/looker/docs/studio/function-list)"]]