PHP date_create_from_format()Functions

PHP Date/TimePHP Date/Time Reference Manual

Examples

Returns a new DateTime object formatted according to the specified format:

<?php
$date=date_create_from_format("j-M-Y","15-Mar-2013");
?>

Run 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 use.formatThe format parameter string can use the following characters:
  • d - Day of the month, with leading zero
  • j - Day of the month, without leading zero
  • 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 (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 - Timezone identifiers
  • U - Seconds elapsed since the Unix epoch
  • (space)
  • # - One of the following separators: ;, :, /, ., ,, -, (, )
  • ? - A random byte
  • * - Random bytes until the next separator/digit
  • ! - Resets all fields to the Unix epoch
  • | - If all fields have not been parsed yet, resets all fields to the Unix epoch
  • + - If present, trailing data in the string will cause a warning, not an error
time Required. Specifies a date/time string. NULL indicates the current date/time.
timezone Optional. Specifiestimethe timezone. Defaults to the current timezone.

Technical Details

Return value: Returns a DateTime object on success, or FALSE on failure.
PHP Version: 5.3+


PHP Date/TimePHP Date/Time Reference Manual Other Extensions