Date Time

<?php
	/* Set time zone */
	date_default_timezone_set("Asia/Kolkata");
	
	/* Show current date in d-m-y format */
	echo date("d-m-Y")."<br />";
	
	/* Show current date and time of GMT */
	echo gmdate("d-m-Y h:i:sa T")."<br />";
	
	/* Show current date and time in Unix timestamp */
	echo strtotime("now")."<br />";
	
	/* Show current time in Unix timestamp of GMT */
	echo gmmktime()."<br />";
	
	/* Add one year to todays date */
	echo date('Y-m-d', strtotime('+1 year'))."<br />";
	
	/* Add one month to todays date */
	echo date('Y-m-d', strtotime('+1 month'))."<br />";
	
	/* Show tomorrow's date  */
	echo date('Y-m-d', strtotime('+1 day'))."<br />";
	
	/* Show previous year's date */
	echo date('Y-m-d', strtotime('-1 year'))."<br />";
	
	/* Show previous month's date */
	echo date('Y-m-d', strtotime('-1 month'))."<br />";
	
	/* Show yesterday's date */
	echo date('Y-m-d', strtotime('-1 day'))."<br />";
	
	/* Convert current date and time into Unix timestamp */
	echo strtotime("2015-02-07 19:04 IST")."<br />";
	
	/* Convert Unix timestamp in readable date and time format */
	$date = new DateTime("@1430993424");
	$date->setTimezone(new DateTimeZone('Etc/GMT+10'));
	echo  $date->format('Y M d D H:i:s T')."<br />";
	
	/* Get difference between of two dates */
	$datediff = strtotime("1-4-2015 01.00". ' '."GMT") - strtotime("now");
	echo floor($datediff/(60*60*24));
?>




/* Output */
29-05-2015
28-05-2015 07:01:40pm GMT
1432839700
1432839700
2016-05-29
2015-06-29
2015-05-30
2014-05-29
2015-04-29
2015-05-28
1423328640
2015 May 07 Thu 00:10:24 GMT+10
-58

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!