ABCDEFGHIJKLMNOPQRSTUVWXYZ
1
This is a comparison between the use of datetime format patterns across RDBMS'.
2
Note, this doc tries to cover the pattern elements accepted by each system and does not cover all the semantics related details.
(e.g. What to do when "YYYY" format is compared with "018" as input)
3
Note2, the information in the table below is from each system's documentation (links on the right) and not neccessarily based on running actual SQL queries.
4
5
Impala-SimpleDateFormat
SQL:2016Oracle 18PostgreSQL 11Vertica 9IBM DB2 11.1Not supported
6
4 digit YearyyyyYYYYYYYYYYYYYYYYYYYY
7
Signed yearSYYYY
8
More than 4 digit Year
YYYY with a non-digit separator
YYYY
9
last 3 digit of YearyyyYYYYYYYYYYYYYYY (First digit from current year)Sources:
10
last 2 digit of Yearyy - This is 2 digit round yearYYYYYYYYYY (First 2 digits from current year)
Impala-Java format:
https://github.com/apache/impala/blob/master/be/src/runtime/datetime-parse-util.h
11
last 1 digit of Yeary - Reads until the first separator and acts accoring to how many digits it finds.YYYYY (First 3 digits from current year)SQL:2016
https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016
12
4 digit round yearRRRRRRRRRRRROracle
https://docs.oracle.com/en/database/oracle/oracle-database/18/sqlrf/Format-Models.html#GUID-EAB212CF-C525-4ED8-9D3F-C76D08EEBC7A
13
2 digit round yearRRRRRRPostgreSQL
https://www.postgresql.org/docs/11/functions-formatting.html
14
Year with commaY,YYYY,YYYY,YYYVertica
https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/SQLReferenceManual/Functions/Formatting/TemplatePatternsForDateTimeFormatting.htm?tocpath=SQL%20Reference%20Manual%7CSQL%20Functions%7CFormatting%20Functions%7CTemplate%20Patterns%20for%20Date%2FTime%20Formatting%7C_____0
15
4digit year containing calendar weekIYYYIYYYIYYYIBM DB2
https://www.ibm.com/support/knowledgecenter/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0007107.html
16
3digit year containing calendar weekIYYIYYIYY
17
2digit year containing calendar weekIYIYIY
18
1digit year containing calendar weekIII
19
Spelled out yearYEAR | SYEAR
20
MonthMMMMMMMMMMMM
21
Month 1 digitM
22
Name of MonthMMMMONTH | Month | month (Locale dependent)MONTH | Month | monthMONTH | Month | monthMONTH | Month | month (Locale dependent)
23
Abbrev. name of MonthMON | Mon | mon (Locale dependent)MON | Mon | monMON | Mon | monMON | Mon | mon (Locale dependent)
24
Day of Month (1-31)ddDDDDDDDDDD
25
Day 1 digitd
26
Day of Year (1-366)DDDDDDDDDDDDDDD
27
Day of week (1-7)DDD (Sunday is 1)D (Locale dependent)
28
Day of ISO week-numbering year (1st day is Monday)IDDD
29
Name of dayDAYDay | Day | dayDay | Day | dayDay | Day | day (Locale dependent)
30
Abbrev. name of dayDYDY | Dy | dyDY | Dy | dyDY | Dy | dy (Locale dependent)
31
12 hourHH | HH12HH | HH12HH | HH12HH12HH | HH12
32
24 hourHHHH24HH24HH24HH | HH24HH24
33
Hour 1 digitH
34
MinutemmMIMIMIMIMI
35
Minute 1 digitm
36
Second of MinutessSSSSSSSSSS
37
Second of Day (0-86399)SSSSSSSSSSSSSSSSSSSSSSS
38
Second 1 digits
39
Fractional SecondS | ... | SSSSSSSSSFF[1..9]FF[1..9]FF[1..12]
40
Millisecond (000-999)MSMS
41
Microsecond (00000-999999)USUSNNNNNN Same as FF6
42
AMA.M.AM | A.M.AM | A.M. | am | a.m.AM | A.M. | am | a.m.
AM | A.M. (Locale dependent)
43
PMP.M.PM | P.M.PM | P.M. | pm | p.m.PM | P.M. | pm | p.m.
PM | P.M. (Locale dependent)
44
Timezone hour
At the end of the format string:
+/-hh:mm
+/-hhmm
+/-hh
TZHTZHTZH
45
Timezone minSee aboveTZMTZMTZM
46
Daylight saving infoTZD
47
Timezone regionTZR
48
Timezone nameTZ | tzTZ | tz
49
Timezone offset from UTCOF
50
SeparatorAny non-alphanumeric char- . / , ' ; : <space>- . / , ; : <space>Not mentioned in docsNot mentioned in docs- . / , ' ; : <space>
Separator in format doesn't have to match the separator in input.
e.g. "YYYY/MM" matches "2019-11"
51
Nested strings"text""text"Not mentioned in docs
52
Non pattern charsErrorCopied verbatimCopied Verbatim
53
ADAD | A.D.AD | A.D. | ad | a.d.AD | A.D. | ad | a.d.
54
BCBC | B.C.BC | B.C. | bc | b.c.BC | B.C. | bc | b.c.
55
CenturyCCCCCC
56
Signed centurySCC
57
Fill mode modifiersFM | FX (Prefix, affects whole input)FM | FX (Affects next 'section' only)FM | FX (Affects next 'section' only)
58
ISO Week of year (1-53)IWIWIW
59
Week of year from 1st JanWWWWWW
60
Week of Month from 1st day of MonthWWW
61
Julian day (# of days since January 1, 4712 BC)JJJJ
62
Quarter of year (1-4)QQQ
63
Roman numeral monthRMRM | rmRM | rm
64
Local radix char (e.g. "3.1" vs "3,1")X
65
Ordinal number suffix (th, rd, nd)THTH | thTH | th
66
Spelled numberSP
67
Spelled, ordinal numberSPTH | THSP
68
Translation mode (print localized names)TM (Basically this uses locale for patterns like 'Mon' etc)
to_char(my_date, 'TMMonth')
TM (Basically this uses locale for patterns like 'Mon' etc)
to_char(my_date, 'TMMonth')
69
Julian day modifierJULIAN | JD | J
70
Next field is timeT
71
Case insensitive format elementsWith some exceptions the format elements are case insensitive
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100