i have two time values say starttime=23:00:00 and estimation time=00:45:00 now i want to add starttime and estimation time and store it in a variable i did like this
$add = abs(strtotime($starttime) + strtotime($estimationtime));
and now i have to compare a new time say currenttime or any other time interval (23:50:00)
if($time >=$starttime && $time <=$add)
{
$message=array("message"=>"there is an appointment");
}
if i echo $add i am not getting the right format it shows 2675756700
pls help me to solve this
If you want to echo your $add
variable in a readable form you have to format it first.
echo(date("H:i:s", $add));
strtotime() returns a timestamp, which is the number of seconds since Jan 1/1970. You cannot compare this to a formatted time value - it's just an integer.
So basically, you're doing the equivalent of:
$add = 1 + 2; // 3
if (3 >= '23:50:00') ...
if you want to compare time values as timestamps, you'll have to convert EVERYTHING to timestamps. Or, you could use the DateTime object, which'll handle a lot of this sort of thing for you automatically.