Page 1 of 1

Get time elapsed from a date to current date

Posted: Thu Jun 26, 2003 12:30 pm
by Cruzado_Mainfrm
I want to get the time that have elapsed from a date
and check if 48 hours have elapsed then evaluate to true, if not, false

Code: Select all

$firstdate = strtotime("1/1/2001 13:0:0");  //ex, this date is just taken from a DB so it could be anything
$currentdate = date("H:m:s");
$result = ???? in
thnx in advance

Posted: Thu Jun 26, 2003 2:36 pm
by twigletmac
Timestamps are likely to be useful here:

Code: Select all

$date1 = mktime(13, 0, 0, 1, 1, 2001);
$date2 = mktime(-48); // 48 hours ago

if ($date1 <= $date2) {
    // date is at least 48 hours ago
} else {
    // date is less than 48 hours ago
}
Mac

Posted: Thu Jun 26, 2003 5:15 pm
by Cruzado_Mainfrm
thnx i guess that would help :D

Posted: Thu Jun 26, 2003 6:28 pm
by Cruzado_Mainfrm
wouldn't that be like:

Code: Select all

<?php

$date1 = mktime(13, 0, 0, 1, 1, 2001); 
$date2 = mktime(date("H")-48); // 48 hours ago   <--change

if ($date1 <= $date2) { 
    // date is at least 48 hours ago 
} else { 
    // date is less than 48 hours ago 
}

?>
any ideas? i think i have to get the current time, and subtract 48 hours from it, cuz when i use -48 alone it sends me one day back...

Posted: Fri Jun 27, 2003 3:49 am
by twigletmac
That's weird, I'm sure it worked for me :? . Let me have a test again.

Mac

Posted: Fri Jun 27, 2003 3:51 am
by twigletmac
Stick with your way, someone will be able to tell me (hopefully since I'm having a brain fart) why my way didn't work as expected (didn't take me back exactly 48 hours either).

Mac

Posted: Fri Jun 27, 2003 7:28 am
by Cruzado_Mainfrm
thankx anyway, that gave me the idea :)