Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

date_create_from_format()

Example

Return a new DateTime object created from a string formatted according to the specified format.

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

Definition and Usage

The date_create_from_format() function returns a new DateTime object based on the specified format.

Syntax

date_create_from_format(format, time, timezone)

Parameter Values

Parameter

Description

format

Required. Specifies the format to use. The format parameter string can include the following characters:

  • d – Day of the month with leading zeros
  • j – Day of the month without leading zeros
  • D – Abbreviated weekday name (e.g., Mon, Tue)
  • l – Full weekday name (e.g., Monday, Tuesday)
  • S – English suffix for the day of the month (e.g., st, nd, rd, th)
  • F – Full month name (e.g., January, February)
  • M – Abbreviated month name (e.g., Jan, Feb)
  • m – Month with leading zeros (01-12)
  • n – Month without leading zeros (1-12)
  • Y – Full year (e.g., 2013)
  • y – Two-digit year (e.g., 13)
  • a and A – am or pm
  • g – 12-hour format without leading zeros
  • G – 24-hour format without leading zeros
  • h – 12-hour format with 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 – Timezone identifier
  • U – Seconds since Unix Epoch
  • (space)
  • # – One of the following separators: ;, :, /, ., ,, -, (, )
  • ? – A random byte
  • * – Random bytes until the next separator or digit
  • ! – Resets all fields to Unix Epoch
  • | – Resets all fields to Unix Epoch if they haven’t been parsed yet
  • + – If present, trailing data in the string will cause a warning rather than an error

time

Required. Specifies a date/time string. If NULL, the current date/time is used.

timezone

Optional. Specifies the timezone for the time. Defaults to the current timezone.

Technical Details

Return Value:

Returns a new DateTime object on success; FALSE on failure.

PHP Version:

5.3+