Possible Duplicate:
How to compare two time in PHP
Hi I am new in time functions in php, i have,
@$download_time = date('d-m-Y H:i:s', $dec_time);
$current_time = date('d-m-Y H:i:s');
$diff = abs(strtotime($current_time) - strtotime($download_time));
$time=65 // $time is in seconds
Now I want to compare if ($diff < $time) how can I compare with this two values.
If
$dec_timeis a unix timestamp, then simply:Else if it is a textual representation:
Be aware of using needless variables if it’s doesn’t needed later, because you can save a lot of memory if keep an eye of this. If the server’s PHP version is above 5.2, then you can use the DateTime class wich gives you a lot of extended functionality.
I didn’t understood why is the
abs()because the download time should be at the past.Notice:
Keep the
@‘s away from your code, because it costs a lot of additional calculations for the PHP interpreter, maybe it is longer to type, but test if the variable exists before, like: