Format elements in GoogleSQL

GoogleSQL for Spanner supports the following format elements.

Format elements for date and time parts

Many GoogleSQL parsing and formatting functions rely on a format stringto describe the format of parsed or formatted values. A format string representsthe textual form of date and time and contains separate format elements that areapplied left-to-right.

These functions use format strings:

Format strings generally support the following elements:

Format elementTypeDescriptionExample
%ADATE
TIMESTAMP
The full weekday name (English).Wednesday
%aDATE
TIMESTAMP
The abbreviated weekday name (English).Wed
%BDATE
TIMESTAMP
The full month name (English).January
%bDATE
TIMESTAMP
The abbreviated month name (English).Jan
%CDATE
TIMESTAMP
The century (a year divided by 100 and truncated to an integer) as a decimal number (00-99).20
%cTIMESTAMP
The date and time representation (English).Wed Jan 20 21:47:00 2021
%DDATE
TIMESTAMP
The date in the format %m/%d/%y.01/20/21
%dDATE
TIMESTAMP
The day of the month as a decimal number (01-31).20
%eDATE
TIMESTAMP
The day of month as a decimal number (1-31); single digits are preceded by a space.20
%FDATE
TIMESTAMP
The date in the format %Y-%m-%d.2021-01-20
%GDATE
TIMESTAMP
TheISO 8601 year with century as a decimal number. Each ISO year begins on the Monday before the first Thursday of the Gregorian calendar year. Note that %G and %Y may produce different results near Gregorian year boundaries, where the Gregorian year and ISO year can diverge.2021
%gDATE
TIMESTAMP
TheISO 8601 year without century as a decimal number (00-99). Each ISO year begins on the Monday before the first Thursday of the Gregorian calendar year. Note that %g and %y may produce different results near Gregorian year boundaries, where the Gregorian year and ISO year can diverge.21
%HTIMESTAMP
The hour (24-hour clock) as a decimal number (00-23).21
%hDATE
TIMESTAMP
The abbreviated month name (English).Jan
%ITIMESTAMP
The hour (12-hour clock) as a decimal number (01-12).09
%jDATE
TIMESTAMP
The day of the year as a decimal number (001-366).020
%kTIMESTAMP
The hour (24-hour clock) as a decimal number (0-23); single digits are preceded by a space.21
%lTIMESTAMP
The hour (12-hour clock) as a decimal number (1-12); single digits are preceded by a space. 9
%MTIMESTAMP
The minute as a decimal number (00-59).47
%mDATE
TIMESTAMP
The month as a decimal number (01-12).01
%nAllA newline character.
%PTIMESTAMP
When formatting, this is either am or pm.
This can't be used with parsing. Instead, use %p.
pm
%pTIMESTAMP
When formatting, this is either AM or PM.
When parsing, this can be used with am, pm, AM, or PM.
PM
%QDATE
TIMESTAMP
The quarter as a decimal number (1-4).1
%RTIMESTAMP
The time in the format %H:%M.21:47
%STIMESTAMP
The second as a decimal number (00-60).00
%sTIMESTAMP
The number of seconds since 1970-01-01 00:00:00. Always overrides all other format elements, independent of where %s appears in the string. If multiple %s elements appear, then the last one takes precedence.1611179220
%TTIMESTAMP
The time in the format %H:%M:%S.21:47:00
%tAllA tab character.
%UDATE
TIMESTAMP
The week number of the year (Sunday as the first day of the week) as a decimal number (00-53).03
%uDATE
TIMESTAMP
The weekday (Monday as the first day of the week) as a decimal number (1-7).3
%VDATE
TIMESTAMP
TheISO 8601 week number of the year (Monday as the first day of the week) as a decimal number (01-53). If the week containing January 1 has four or more days in the new year, then it's week 1; otherwise it's week 53 of the previous year, and the next week is week 1.03
%WDATE
TIMESTAMP
The week number of the year (Monday as the first day of the week) as a decimal number (00-53).03
%wDATE
TIMESTAMP
The weekday (Sunday as the first day of the week) as a decimal number (0-6).3
%XTIMESTAMP
The time representation in HH:MM:SS format.21:47:00
%xDATE
TIMESTAMP
The date representation in MM/DD/YY format.01/20/21
%YDATE
TIMESTAMP
The year with century as a decimal number.2021
%yDATE
TIMESTAMP
The year without century as a decimal number (00-99), with an optional leading zero. Can be mixed with %C. If %C isn't specified, years 00-68 are 2000s, while years 69-99 are 1900s.21
%ZTIMESTAMP
The time zone name.UTC-5
%zTIMESTAMP
The offset from the Prime Meridian in the format +HHMM or -HHMM as appropriate, with positive values representing locations east of Greenwich.-0500
%%AllA single % character.%
%EzTIMESTAMP
RFC 3339-compatible numeric time zone (+HH:MM or -HH:MM).-05:00
%E<number>STIMESTAMP
Seconds with <number> digits of fractional precision.00.000 for %E3S
%E*STIMESTAMP
Seconds with full fractional precision (a literal '*').00.123456789
%E4YDATE
TIMESTAMP
Four-character years (0001 ... 9999). Note that %Y produces as many characters as it takes to fully render the year.2021

Examples:

SELECTFORMAT_DATE("%b-%d-%Y",DATE"2008-12-25")ASformatted;/*-------------+ | formatted   | +-------------+ | Dec-25-2008 | +-------------*/
SELECTFORMAT_TIMESTAMP("%b %Y %Ez",TIMESTAMP"2008-12-25 15:30:00+00")ASformatted;/*-----------------+ | formatted       | +-----------------+ | Dec 2008 +00:00 | +-----------------*/
SELECTPARSE_DATE("%Y%m%d","20081225")ASparsed;/*------------+ | parsed     | +------------+ | 2008-12-25 | +------------*/
SELECTPARSE_TIMESTAMP("%c","Thu Dec 25 07:30:00 2008")ASparsed;-- Display of results may differ, depending upon the environment and-- time zone where this query was executed./*------------------------+ | parsed                 | +------------------------+ | 2008-12-25T15:30:00Z   | +------------------------*/

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.