1echo date('Y-m-d H:i:s');
2
3//Output something like this:
4//2021-07-30 10:07:45
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
1strtotime("now");
2
3// strtotime is a function that will take a string parameter
4// that specifies a date, and returns a unix time stamp bassed
5// on that
6
7echo strtotime("2020-02-24");
8
9// prints: 1582502400
1# Current Time
2date_default_timezone_set("America/New_York");
3echo "The time is " . date("h:i:sa");