date_format
Description
The date_format of Date / Time for PHP returns date formatted according to given format.
Syntax
date_format(
DateTimeInterface $object,
string $format
): stringParameters
object
A DateTime object returned by date_create()
format
The format of the outputted date string.
| Day | Description | Example |
|---|---|---|
| d | Day of the month with leading zeros, 2 digits | 01 - 31 |
| D | Short textual representation of the day of the week, three letters | Mon - Sun |
| j | Day of the month without leading zeros | 1 - 31 |
| l (lowercase L) | Full textual representation of the day of the week | Sunday - Saturday |
| N | ISO-8601 numeric representation of the day of the week | 1 - 7 (Monday - Sunday) |
| S | English ordinal suffix for the day of the month, 2 characters | st, nd, rd, th |
| w | Numeric representation of the day of the week | 0 - 6 (Sunday - Saturday) |
| z | Day of the year | 0 - 365 |
| Week | Description | Example |
|---|---|---|
| W | ISO-8601 week of the year, weeks start on Monday | 1 - 52 |
| Month | Description | Example |
|---|---|---|
| F | Full textual representation of a month | January - December |
| m | Numeric representation of a month with leading zeros, 2 digits | 01 - 12 |
| M | Short textual representation of a month, three letters | Jan - Dec |
| n | Numeric representation of a month without leading zeros | 1 - 12 |
| t | Number of days in the given month | 28 - 31 |
| Year | Description | Example |
|---|---|---|
| L | Whether it's a leap year | 1 (leap year), 0 (otherwise) |
| o | ISO-8601 week-numbering year. The same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. | Example: 1999 |
| Y | 4 digit representation of a year | Example: 1999 |
| y | 2 digit representation of a year | 00 - 99 |
| Time | Description | Example |
|---|---|---|
| a | Lowercase Ante meridiem and Post meridiem | am, pm |
| A | Uppercase Ante meridiem and Post meridiem | AM, PM |
| B | Swatch Internet time | 000 - 999 |
| g | 12-hour format of an hour without leading zeros | 1 - 12 |
| G | 24-hour format of an hour without leading zeros | 0 - 23 |
| h | 12-hour format of an hour with leading zeros | 01 - 12 |
| H | 24-hour format of an hour with leading zeros | 00 - 23 |
| i | Minutes with leading zeros | 00 - 59 |
| s | Seconds with leading zeros | 00 - 59 |
| u | Microseconds. Note: date() will always generate 000000 since it takes an integer parameter, whereas DateTime::format() does support microseconds if DateTime was created with microseconds. | Example: 654321 |
| v | Milliseconds. Same note as u. | Example: 654 |
| Timezone | Description | Example |
|---|---|---|
| e | Timezone identifier | Examples: UTC, GMT, Atlantic/Azores |
| I (uppercase i) | Whether or not the date is in daylight saving time | 1 (daylight saving time), 0 (otherwise) |
| O | Difference to Greenwich time (GMT) without colon between hours and minutes | Example: +0200 |
| P | Difference to Greenwich time (GMT) with colon between hours and minutes | Example: +02:00 |
| T | Timezone abbreviation | Examples: EST, MDT ... |
| Z | Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. | -43200 - 50400 |
| Full | Description | Example |
|---|---|---|
| c | ISO 8601 date | Example: 2001-02-03T04:05:06+00:00 |
| r | RFC 2822 formatted date | Example: Sat, 03 Feb 2001 04:05:06 +0000 |
| U | Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) | See also time() |
Unrecognized characters in the format string will be printed as-is. The Z format will always return 0 when using gmdate(). Note: Since this function only accepts integer timestamps the u format character is only useful when using the date_format() function with user based timestamps created with date_create().
Return
Returns the formatted date string on success.
Examples
1 · object format
<? $object = date_create(); $format = "Y-m-d h:i:s.u"; $return = date_format($object, $format); echo $return;
2026-01-14 11:12:03.491574
Links
Date / Time
- checkdate
- date
- date_add
- date_create
- date_create_from_format
- date_create_immutable
- date_create_immutable_from_format
- date_date_set
- date_default_timezone_get
- date_default_timezone_set
- date_diff
- date_get_last_errors
- date_interval_create_from_date_string
- date_interval_format
- date_isodate_set
- date_modify
- date_offset_get
- date_parse
- date_parse_from_format
- date_sub
- date_sun_info
- date_sunrise
- date_sunset
- date_time_set
- date_timestamp_get
- date_timestamp_set
- date_timezone_get
- date_timezone_set
- getdate
- gettimeofday
- gmdate
- gmmktime
- gmstrftime
- idate
- localtime
- microtime
- mktime
- strftime
- strptime
- strtotime
- time
- timezone_abbreviations_list
- timezone_identifiers_list
- timezone_location_get
- timezone_name_from_abbr
- timezone_name_get
- timezone_offset_get
- timezone_open
- timezone_transitions_get
- timezone_version_get