# The original dimension group - hidden so that users can only choose from the formatted dates date and week timeframes
dimension_group: created {
hidden: yes
type: time
timeframes: [
raw,
time,
date,
hour,
hour_of_day,
time_of_day,
week,
month,
quarter,
year
]
sql: ${TABLE}.created_at ;;
}
# The customized timeframes, organized in the Explore field picker under the group label Created date
dimension: date_formatted {
group_label: "Created date"
label: "Date"
type: date_raw
sql: ${created_date} ;;
html: {{ rendered_value | date: "%b %d, %y" }};;
}
dimension: week_formatted {
group_label: "Created date"
label: "Week"
type: date_raw
sql: ${created_week} ;;
html: {{ rendered_value | date: "Week %U (%b %d)" }};;
}
strftime Reference
下表列出了各种 strftime 格式。请注意,并非所有格式都能在 Looker 中按预期呈现。
说明符
已被替换为
示例
%a
星期几的缩写名称 *
星期四
%A
星期几的全名*
星期四
%b
月份的缩写名称 *
8 月
%B
完整月份名称*
8 月
%c
日期和时间表示法 *
2001 年 8 月 23 日星期四 14:55:02
%C
年份除以 100 并截断为整数 (00-99)
20
%d
日期(前面补零,01-31)
23
%D
短格式日期(MM/DD/YY),相当于 %m/%d/%y
08/23/01
%e
日期(用空格填充,1-31)
23
%F
短格式 YYYY-MM-DD 日期,相当于 %Y-%m-%d
2001-08-23
%g
基于周的年份,最后两位数字 (00-99)
1
%G
基于周的年
2001
%h
月份的缩写名称*(与 %b 相同)
8 月
%H
24 小时制的小时数 (00-23)
14
%I
12 小时制的小时数 (01-12)
02
%j
年份中的某一天 (001-366)
235
%k
24 小时制的小时数,个位数前面附加一个空格 (0-23)
14
%l
12 小时制的小时数,个位数前面带有空格 (0-12)
2
%m
用十进制数 (01-12) 表示的月份
8
%M
分钟 (00-59)
55
%n
换行符 ('\n')
%P
上午或下午标识(使用小写字母)
pm
%r
12 小时制时间*
下午 2:55:02
%R
24 小时制 HH:MM 时间,相当于 %H:%M
14:55
%s
从公元纪年 1970 年 1 月 1 日 00:00:00 +0000 (UTC) 开始计算的秒数
1566236649
%S
秒 (00-61)
2
%t
水平制表符 ('\t')
%T
ISO 8601 时间格式 (HH:MM:SS),相当于 %H:%M:%S
14:55:02
%u
ISO 8601 星期几(星期一为 1)(1-7)
4
%U
周数(以第一个星期日为第一周的第一天)(00-53)
33
%V
ISO 8601 周数 (01-53)
34
%w
星期几(以星期日为 0 的十进制数)(0-6)
4
%W
周数(以第一个星期一为第一周的第一天)(00-53)
34
%x
日期表示法 *
2001 年 8 月 23 日
%X
时间表示法*
14:55:02
%y
年份,最后两位数字(00-99)
1
%Y
年
2001
%z
时区中的 ISO 8601 偏移量(1 分钟=1、1 小时=100)如果无法确定时区,则不显示任何字符
[[["易于理解","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-07-30。"],[],[],null,["# How to use Liquid to format dates\n\nIn some situations, you may want to change the way Looker formats dates.\n\n\nFor example, if you're building Explores and dashboards for users in Europe, any dates that are in an all-numeric format should appear in the order Day-Month-Year. For example, June 7th, 2019 should be formatted as `07/06/2019` or `Jun 07, 2019`. Looker's default format renders the date as `2019-06-07`. While you can use SQL functions like `DATE_FORMAT()` to change a date format, you may not want to write everything in plain SQL.\n\nUsing Liquid in the `html` parameter\n------------------------------------\n\n| **Note:** When [downloading content](/looker/docs/downloading), Liquid formatting applied in the [`html`](/looker/docs/reference/param-field-html) parameter is not applied to text-based download formats, such as TXT, CSV, Excel, or JSON.\n\n\nYou can use [Liquid formatting](https://shopify.github.io/liquid/filters/date/) in the [`html`](/looker/docs/reference/param-field-html) parameter of a dimension to change the format of any field that uses a valid date format. Since Liquid expects a valid date, it is best to use the timeframes from an existing dimension group. You can't change the week or month *numbers*, because those are returned as integers.\n| **Caution:** Liquid formatting is not supported for the [`month`](/looker/docs/reference/param-field-dimension-group#time_type) timeframe.\n\n\nFor example, you can format `${created_date}` to render as `Aug 23 22` instead of the Looker default `2022-08-23`: \n\n```\n\n dimension: date_formatted {\n sql: ${created_date} ;;\n html:{{ rendered_value | date: \"%b %d, %y\" }};;\n }\n\n\n```\n\n\nThe format for the string syntax `\"%b %d, %y\"` is the same as [`strftime`](http://strftime.net).\n\n\nBecause the `html` parameter uses Liquid formatting, the original value of the timeframe is not changed --- only the way that the value is rendered to the user. This ensures that the order in which dates appear in a query will not change.\n\n\nFollowing are some other examples you can use. The larger reference of available formats is at the bottom of this page.\n\nExample\n-------\n\n\nThe following example of an Explore query shows **Order Items Date** and **Orders Items Week** formatted differently and organized under a **Created date** group label to simulate a date dimension group in the Explore field picker.\n\n\nThe custom formatting shows users which date and which week number of the year correspond to the largest **Count of Items** values in descending order.\n\n\nSee the [`group_label` documentation page](/looker/docs/reference/param-field-group-label) to learn more about using the `group_label` parameter.\n\n\n### The LookML\n\n\nThe Explore example uses the following LookML: \n\n```\n\n\n# The original dimension group - hidden so that users can only choose from the formatted dates date and week timeframes\n dimension_group: created {\n hidden: yes\n type: time\n timeframes: [\n raw,\n time,\n date,\n hour,\n hour_of_day,\n time_of_day,\n week,\n month,\n quarter,\n year\n ]\n sql: ${TABLE}.created_at ;;\n }\n\n# The customized timeframes, organized in the Explore field picker under the group label Created date\n dimension: date_formatted {\n group_label: \"Created date\"\n label: \"Date\"\n type: date_raw\n sql: ${created_date} ;;\n html: {{ rendered_value | date: \"%b %d, %y\" }};;\n }\n\n dimension: week_formatted {\n group_label: \"Created date\"\n label: \"Week\"\n type: date_raw\n sql: ${created_week} ;;\n html: {{ rendered_value | date: \"Week %U (%b %d)\" }};;\n }\n\n\n```\n\n`strftime Reference`\n--------------------\n\n\nThe following table lists various `strftime` formats. Please note that not all formats may render as expected in Looker.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]