strtotime to get Unix timestamp

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

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

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
What is the weekday today ?
echo date('D',strtotime('now'))
$pub_date='2024-02-11T15:36:25Z'
$my_date=date('d-M-Y h:i:s', strtotime($pub_date));

Check all the Date and time formats here
Using strtotime with date() to get formatted date and time output.
Code Output
date('m-d-Y',strtotime('now'))03-29-2024
date('m-d-Y',strtotime('11 July 2016'))07-11-2016
date('m-d-Y',strtotime('+1 day'))03-30-2024
date('m-d-Y',strtotime('+1 week'))04-05-2024
date('m-d-Y',strtotime('+1 month'))04-29-2024
date('m-d-Y',strtotime('+1 month 3 days'))05-02-2024
date('m-d-Y',strtotime('+2 months -1 day'))05-28-2024
date('m-d-Y',strtotime('Wednesday'))04-03-2024
date('m-d-Y',strtotime('Sunday +1 day'))04-01-2024
date('m-d-Y',strtotime('first day of this month'))03-01-2024
date('m-d-Y',strtotime('last day of this month'))03-31-2024
date('m-d-Y',strtotime('first day of next month'))04-01-2024
date('m-d-Y',strtotime('last day of next month'))04-30-2024
date('m-d-Y',strtotime('first day of previous month'))02-01-2024
date('m-d-Y',strtotime('last day of previous month'))02-29-2024
date('m-d-Y',strtotime('+5 years '))03-29-2029
With Date & Time
date('m-d-Y H:i:s',strtotime('+1 hour '))03-29-2024 11:52:22
date('m-d-Y H:i:s',strtotime('+10 minutes '))03-29-2024 11:02:22
date('m-d-Y H:i:s',strtotime('+20 seconds '))03-29-2024 10:52:42
date('m-d-Y',strtotime('last day of next month +1 Hour'))04-30-2024 : 11
date('m-d-Y',strtotime('first day of next month +1 Hour 20 minutes'))04-01-2024 : 12 : 12 : 22
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('m-d-Y',strtotime('12-06-2018 next Monday '))06-18-2018
date('d-M-Y',strtotime('07-06-2018 next Wednesday'))13-Jun-2018
Date object by using similar string by using DateTime() Date Picker using JQuery

Other ways to get Unix Timestamp

Function Description
mktime() getting time stamp of input date and time
gettimestamp()Getting Timestamp from date object
PHP Date Functions Adding Date by using DateInterval Today Date using Date()
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here





    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer