PHP date_create_from_format() Function
PHP Date/Time Reference Manual
Example
Return a new DateTime object formatted according to a specified format:
Run Example »
Definition and Usage
The date_create_from_format() function returns a new DateTime object formatted according to a specified format.
Syntax
date_create_from_format(
format,time,timezone);
| Parameters |
Description |
| format |
Required. Specifies the format to use.format The parameter string can use the following characters:
|
d - Day of the month, with leading zeros
j - Day of the month, without leading zeros
D - Day of the week (Mon - Sun)
I - Day of the week (Monday - Sunday)
S - English ordinal suffix for the day of the month (st, nd, rd, th)
F - Month name (January - December)
M - Month name (Jan - Dec)
m - Month (01 - 12)
n - Month (1 - 12)
Y - Year (for example 2013)
y - Year (for example 13)
a and A - am or pm
g - 12-hour format, without leading zeros
h - 12-hour format, with leading zeros
G - 24-hour format, without leading zeros
H - 24-hour format, with leading zeros
i - Minutes, with leading zeros
s - Seconds, with leading zeros
u - Microseconds (up to six digits)
e, O, P, and T - Time zone identifier
U - Seconds since the Unix epoch
(space)
# - One of the following separators: ;, :, /, ., ,, -, (, )
? - A random byte
* - Random bytes until the next separator or digit
! - Resets all fields to the Unix epoch
\| - Resets all fields to the Unix epoch if none have been parsed yet
+ - If present, trailing data in the string causes a warning, not an error
| | *time* | Required. Specifies a date/time string. NULL means the current date/time. | | *timezone* | Optional. Specifies the time zone of *time*. Defaults to the current time zone. |
Technical Details
| Return Value: |
Returns a DateTime object on success, or FALSE on failure. |
| PHP Version: |
5.3+ |
PHP Date/Time Reference Manual