1$today = date("F j, Y, g:i a"); // October 30, 2019, 10:42 pm
2$today = date("D M j G:i:s T Y"); // Wed Oct 30 22:42:18 UTC 2019
3$today = date("Y-m-d H:i:s"); // 2019-10-30 22:42:18(MySQL DATETIME format)
1//Get current date time in PHP
2
3// Simply:
4$date = date('Y-m-d H:i:s');
5
6// Or:
7$date = date('Y/m/d H:i:s');
8
9// This would return the date in the following formats respectively:
10$date = '2012-03-06 17:33:07';
11// Or
12$date = '2012/03/06 17:33:07';
13
14/**
15 * This time is based on the default server time zone.
16 * If you want the date in a different time zone,
17 * say if you come from Nairobi, Kenya like I do, you can set
18 * the time zone to Nairobi as shown below.
19 */
20
21date_default_timezone_set('Africa/Nairobi');
22
23// Then call the date functions
24$date = date('Y-m-d H:i:s');
25// Or
26$date = date('Y/m/d H:i:s');
27
28// date_default_timezone_set() function is however
29// supported by PHP version 5.1.0 or above.
30
1<?php
2/* Unix Timestamp */
3$timestamp = time();
4echo $timestamp . "<br>";
5echo date("d/m/Y", $timestamp);
6?>
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)