1$today = date("F j, Y, g:i a"); // March 10, 2001, 5:16 pm
2$today = date("m.d.y"); // 03.10.01
3$today = date("j, n, Y"); // 10, 3, 2001
4$today = date("Ymd"); // 20010310
5$today = date('h-i-s, j-m-y, it is w Day'); // 05-16-18, 10-03-01, 1631 1618 6 Satpm01
6$today = date('\i\t \i\s \t\h\e jS \d\a\y.'); // It is the 10th day (10ème jour du mois).
7$today = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001
8$today = date('H:m:s \m \e\s\t\ \l\e\ \m\o\i\s'); // 17:03:18 m est le mois
9$today = date("H:i:s"); // 17:16:18
10$today = date("Y-m-d H:i:s"); // 2001-03-10 17:16:18 (le format DATETIME de MySQL)
1<?php
2 // To change the format of an existing date
3 $old_date_format = "20/03/1999";
4 $new_data_format = date("Y-m-d H:i:s", strtotime($old_date_format));
1echo date('d/m/Y h:i:s a'); // 01/02/2020 01:01:30 am
2// d - The day of the month (from 01 to 31)
3// D - A textual representation of a day (three letters)
4// j - The day of the month without leading zeros (1 to 31)
5// l (lowercase 'L') - A full textual representation of a day
6// N - The ISO-8601 numeric representation of a day (1 for Monday, 7 for Sunday)
7// S - The English ordinal suffix for the day of the month (2 characters st, nd, rd or th. Works well with j)
8// w - A numeric representation of the day (0 for Sunday, 6 for Saturday)
9// z - The day of the year (from 0 through 365)
10// W - The ISO-8601 week number of year (weeks starting on Monday)
11// F - A full textual representation of a month (January through December)
12// m - A numeric representation of a month (from 01 to 12)
13// M - A short textual representation of a month (three letters)
14// n - A numeric representation of a month, without leading zeros (1 to 12)
15// t - The number of days in the given month
16// L - Whether it's a leap year (1 if it is a leap year, 0 otherwise)
17// o - The ISO-8601 year number
18// Y - A four digit representation of a year
19// y - A two digit representation of a year
20// a - Lowercase am or pm
21// A - Uppercase AM or PM
22// B - Swatch Internet time (000 to 999)
23// g - 12-hour format of an hour (1 to 12)
24// G - 24-hour format of an hour (0 to 23)
25// h - 12-hour format of an hour (01 to 12)
26// H - 24-hour format of an hour (00 to 23)
27// i - Minutes with leading zeros (00 to 59)
28// s - Seconds, with leading zeros (00 to 59)
29// u - Microseconds (added in PHP 5.2.2)
30// e - The timezone identifier (Examples: UTC, GMT, Atlantic/Azores)
31// I (capital i) - Whether the date is in daylights savings time (1 if Daylight Savings Time, 0 otherwise)
32// O - Difference to Greenwich time (GMT) in hours (Example: +0100)
33// P - Difference to Greenwich time (GMT) in hours:minutes (added in PHP 5.1.3)
34// T - Timezone abbreviations (Examples: EST, MDT)
35// Z - Timezone offset in seconds. The offset for timezones west of UTC is negative (-43200 to 50400)
36// c - The ISO-8601 date (e.g. 2013-05-05T16:34:42+00:00)
37// r - The RFC 2822 formatted date (e.g. Fri, 12 Apr 2013 12:01:05 +0200)
38// U - The seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
1# From a date Object:
2date_format ( DateTimeInterface $object , string $format )
3
4# From the current time
5$dateTime = new \DateTime();
6// or pass a string or int ->`DateTime($date_time)`
7$dateTime->format('y-j-d H:i:s T'); #print ex: 21-2-02 16:00:01 PST
8
9# Or a quick one-liner:
10date('g:i A m-d-Y', strtotime($date_time)); #print ex: 2:00 PM 02-02-2021