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 // 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));
1// In my case I want to print to log my zone time (Rome GMT +2)
2// without changing the default timezone
3// Add +2 hours respect to php time
4$new_time = date("Y-m-d H:i:s", strtotime('+2 hours'));