Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to compare if mytime is 6 hour less than system time or not>

PHP
$mytime="9:10";
$sysdate=date('h:i');

how can I compare them??

thanks in advance
Posted
Updated 25-May-14 11:35am
v2
Comments
Sergey Alexandrovich Kryukov 25-May-14 19:46pm    
"9:10" is not time; this is a string "9:10".
—SA

1 solution

Try this:
PHP
<?php
$mytime = '9:16';
$sysdate = strtotime("now");
$timediff = ($sysdate - strtotime($mytime))/3600;
if ($timediff < 6) {
    echo "less than 6 hours";
} else if ($timediff > 6) {
    echo "more than 6 hours";
} else {
    echo ('exactly 6 hours less');
}
?>

Read more: function.strtotime.php[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900