# 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
以整數 (00-99) 表示的年份 (除以 100 並截斷)
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
am 或 pm 標記 (小寫)
pm
%r
12 小時制時間 *
下午 2:55:02
%R
24 小時制 HH:MM 時間,等同於 %H:%M
14:55
%s
自 Epoch 1970-01-01 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
日期表示法 *
08/23/01
%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"]],["上次更新時間: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"]]