Day |
--- |
--- |
d and j |
Day of the month, 2 digits with or without leading zeros |
01 to 31 or
1 to 31 . (2 digit numbers
higher than the number of days in the month are accepted, in which
case they will make the month overflow. For example using 33 with
January, means February 2nd)
|
D and l |
A textual representation of a day |
Mon through Sun or
Sunday through Saturday . If
the day name given is different then the day name belonging to a
parsed (or default) date is different, then an overflow occurs to
the next date with the given day name. See the
examples below for an explanation.
|
S |
English ordinal suffix for the day of the month, 2
characters. It's ignored while processing. |
st , nd , rd or
th .
|
z |
The day of the year (starting from 0);
must be preceded by Y or y .
|
0 through 365 . (3 digit
numbers higher than the numbers in a year are accepted, in which
case they will make the year overflow. For example using 366 with
2022, means January 2nd, 2023)
|
Month |
--- |
--- |
F and M |
A textual representation of a month, such as January or Sept |
January through December or
Jan through Dec
|
m and n |
Numeric representation of a month, with or without leading zeros |
01 through 12 or
1 through 12 .
(2 digit numbers higher than 12 are accepted, in which case they
will make the year overflow. For example using 13 means January in
the next year)
|
Year |
--- |
--- |
X and x |
A full numeric representation of a year, up to 19 digits,
optionally prefixed by + or
- |
Examples: 0055 , 787 ,
1999 , -2003 ,
+10191 |
Y |
A full numeric representation of a year, up to 4 digits |
Examples: 0055 , 787 ,
1999 , 2003 |
y |
A two digit representation of a year (which is assumed to be in the
range 1970-2069, inclusive)
|
Examples:
99 or 03
(which will be interpreted as 1999 and
2003 , respectively)
|
Time |
--- |
--- |
a and A |
Ante meridiem and Post meridiem |
am or pm |
g and h |
12-hour format of an hour with or without leading zero |
1 through 12 or
01 through 12 (2 digit
numbers higher than 12 are accepted, in which case they will make
the day overflow. For example using 14 means
02 in the next AM/PM period)
|
G and H |
24-hour format of an hour with or without leading zeros |
0 through 23 or
00 through 23 (2 digit
numbers higher than 24 are accepted, in which case they will make
the day overflow. For example using 26 means
02:00 the next day)
|
i |
Minutes with leading zeros |
00 to 59 . (2 digit
numbers higher than 59 are accepted, in which case they will make
the hour overflow. For example using 66 means
:06 the next hour)
|
s |
Seconds, with leading zeros |
00 through 59 (2 digit
numbers higher than 59 are accepted, in which case they will make
the minute overflow. For example using 90 means
:30 the next minute)
|
v |
Fraction in milliseconds (up to three digits) |
Example: 12 (0.12
seconds), 345 (0.345 seconds) |
u |
Fraction in microseconds (up to six digits) |
Example: 45 (0.45
seconds), 654321 (0.654321
seconds) |
Timezone |
--- |
--- |
e , O ,
P and T
|
Timezone identifier, or difference to UTC in hours, or
difference to UTC with colon between hours and minutes, or timezone
abbreviation |
Examples: UTC , GMT ,
Atlantic/Azores or
+0200 or +02:00 or
EST , MDT
|
Full Date/Time |
--- |
--- |
U |
Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) |
Example: 1292177455 |
Whitespace and Separators |
--- |
--- |
(space) |
Zero or more spaces, tabs, NBSP (U+A0), or NNBSP (U+202F)
characters |
Example: "\t" , " " |
# |
One of the following separation symbol: ; ,
: , / , . ,
, , - , ( or
)
|
Example: / |
; ,
: , / , . ,
, , - , ( or
)
|
The specified character. |
Example: - |
? |
A random byte |
Example: ^ (Be aware that for UTF-8
characters you might need more than one ? .
In this case, using * is probably what you want
instead) |
* |
Random bytes until the next separator or digit |
Example: * in Y-*-d with
the string 2009-aWord-08 will match
aWord |
! |
Resets all fields (year, month, day, hour, minute, second,
fraction and timezone information) to zero-like values (
0 for hour, minute, second and fraction,
1 for month and day, 1970
for year and UTC for timezone information) |
Without !, all fields will be set to the
current date and time. |
| |
Resets all fields (year, month, day, hour, minute, second,
fraction and timezone information) to zero-like values if they have
not been parsed yet |
Y-m-d| will set the year, month and day
to the information found in the string to parse, and sets the hour,
minute and second to 0. |
+ |
If this format specifier is present, trailing data in the
string will not cause an error, but a warning instead |
Use DateTimeImmutable::getLastErrors() to find out
whether trailing data was present. |