1<?php
2echo "Today is " . date("Y/m/d") . "<br>";
3echo "Today is " . date("Y.m.d") . "<br>";
4echo "Today is " . date("Y-m-d") . "<br>";
5echo "Today is " . date("l");
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$timestamp = strtotime('2009-10-22');
2
3$day = date('D', $timestamp);
4var_dump($day);
1# Current date
2date_default_timezone_set('Asia/Kolkata');
3echo date("Y-m-d H:i:s");
4
5# Current Time
6date_default_timezone_set("America/New_York");
7echo "The time is " . date("h:i:sa");