PHP date_create_from_format() function
Example
Returns a new DateTime object formatted according to the specified format:
<?php
$date=date_create_from_format("j-M-Y","25-Sep-2016");
?>
Running Example
Definition and Usage
The date_create_from_format() function returns a new DateTime object formatted according to the specified format.
Syntax
date_create_from_format(format,time,timezone);
Parameter |
Description |
format |
Required. Specifies the format to be used.format The parameter string can use the following characters:
- d - The day of the month, with leading zero
- j - The day of the month, without leading zero
- D - Day of the week (Mon-Sun)
- I - Day of the week (Monday-Sunday)
- S - English 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 (e.g., 2013)
- y - Year (e.g., 13)
- a and A - am or pm
- g - 12-hour format, without leading zero
- h - 12-hour format, with leading zero
- G - 24-hour format, without leading zero
- H - 24-hour format, with leading zero
- i - Minutes, with leading zero
- s - Seconds, with leading zero
- u - Microseconds (up to six digits)
- e, O, P, and T - Time zone identifiers
- U - Seconds since Unix epoch
- (Space)
- # - One of the following delimiters: ;, :, /, ., -, (, )
- ? - A random byte
- * - Random bytes until the next delimiter/digit
- ! - Reset all fields to Unix epoch
- | - If all fields have not been parsed, reset all fields to Unix epoch
- + - If present, trailing data in the string will cause a warning, not an error
|
time |
Required. Specifies the date/time string. NULL indicates the current date/time. |
timezone |
Optional. Specifies time of the time zone. The default is the current time zone. |
Technical Details
Return Value: |
Returns a DateTime object on success, or FALSE on failure. |
PHP Version: |
5.3+ |