I have software that needs to determine if the cutoff datetime is greater than 24 hours from now. Here is the code I have to test that.
$date = strtotime("2013-07-13") + strtotime("05:30:00");
if($date > time() + 86400) {
echo 'yes';
} else {
echo 'no';
}
My current date and time is 2013-07-13 2am. As you can see its only 3 hours away.
At my math thats 10800 seconds away. The function I have is returning yes
. To me this is saying the $date
is greater than now plus 86400 seconds when in fact its only 10800 seconds away. Should this not be returning no
?
php $date_now = time(); //current timestamp $date_convert = strtotime('2022-08-01'); if ($date_now > $date_convert) { echo 'greater than'; } else { echo 'Less than'; } ?> Save this answer.
In order to compare those two dates we use the method diff() of the first DateTime object with the second DateTime object as argument. The diff() method will return a new object of type DateInterval .
What is a TimeStamp? A timestamp in PHP is a numeric value in seconds between the current time and value as at 1st January, 1970 00:00:00 Greenwich Mean Time (GMT).
<?php
date_default_timezone_set('Asia/Kolkata');
$date = "2014-10-06";
$time = "17:37:00";
$timestamp = strtotime($date . ' ' . $time); //1373673600
// getting current date
$cDate = strtotime(date('Y-m-d H:i:s'));
// Getting the value of old date + 24 hours
$oldDate = $timestamp + 86400; // 86400 seconds in 24 hrs
if($oldDate > $cDate)
{
echo 'yes';
}
else
{
echo 'no'; //outputs no
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With