strtotime to get Unix timestamp

Strtotime gives Unix timestamp starting from 1st Jan 1970 00:00:00 GMT;

echo strtotime('now');
Output is here
1516089358

Comparing two dates

By using strtotime we can compare two dates and return the highest ( or lowest ) date of them. Here is the code
$dt1='25-12-2015'; // First Date one in a variable
$dt2='01-07-2016'; // Second Date in a variable

$dt11=strtotime($dt1); // Converting first date to timestamp
$dt22=strtotime($dt2); // Converting second date to timestamp

if($dt11 > $dt22){
$dt=$dt1;
}else{
$dt=$dt2;
}
echo "Highest  Date : $dt ";
Output is here
Highest Date : 01-07-2016
Using strtotime with date() to get formatted date and time output
Code Output
date('m-d-Y',strtotime('now'))01-16-2018
date('m-d-Y',strtotime('11 July 2016'))07-11-2016
date('m-d-Y',strtotime('+1 day'))01-17-2018
date('m-d-Y',strtotime('+1 week'))01-23-2018
date('m-d-Y',strtotime('+1 month'))02-16-2018
date('m-d-Y',strtotime('+1 month 3 days'))02-19-2018
date('m-d-Y',strtotime('+2 months -1 day'))03-15-2018
date('m-d-Y',strtotime('Wednesday'))01-17-2018
date('m-d-Y',strtotime('Sunday +1 day'))01-22-2018
date('m-d-Y',strtotime('first day of next month'))02-01-2018
date('m-d-Y',strtotime('last day of next month'))02-28-2018
date('m-d-Y',strtotime('+5 years '))01-16-2023
date('m-d-Y',strtotime('last day of next month +1 Hour'))02-28-2018 : 14
date('m-d-Y',strtotime('first day of next month +1 Hour 20 minutes'))02-01-2018 : 14 : 45 : 58
Fixed Date
date('m-d-Y',strtotime('25-12-2012 +5 years '))12-25-2017
date('m-d-Y',strtotime('25-12-2012 +1 month 1 week '))02-01-2013

Date Picker using JQuery

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
Visitors Rating
Your Rating


Google+



More On Date Object

Post Comment This is for short comments only. Use the forum for more discussions.




Subscribe to our mailing list

* indicates required
Subscribe to plus2net
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2018 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer