ShopMAster Posted March 7, 2007 Share Posted March 7, 2007 Hey guys, When working with dates and times how do I do an if statement like the following: If ($registration_date == NOW() - 1 hour) echo 'yea' The registration field is formated like 2007-08-17 16:58:32 Thanks. Shopmaster Link to comment https://forums.phpfreaks.com/topic/41644-working-with-dates-and-times/ Share on other sites More sharing options...
AV1611 Posted March 7, 2007 Share Posted March 7, 2007 I think you have to convert time to unix time then subtract 360 seconds, then clause If($reg_date >= $now-360){echo 'YUP'} Link to comment https://forums.phpfreaks.com/topic/41644-working-with-dates-and-times/#findComment-201787 Share on other sites More sharing options...
ShopMAster Posted March 7, 2007 Author Share Posted March 7, 2007 how do you convert the time to a unix time? Link to comment https://forums.phpfreaks.com/topic/41644-working-with-dates-and-times/#findComment-201799 Share on other sites More sharing options...
kenrbnsn Posted March 7, 2007 Share Posted March 7, 2007 Use the strtotime() function to convert an arbitrary date/time string to a UNIX timestamp. Use the time() function to get the UNIX timestamp of the current date/time. BTW, there are 3600 seconds in an hour. You can get "now - 1 hour" a few different ways: <?php $now = time(); $lasthour = $now - 3600; // or $lasthour1 = strtotime("-1 hour"); // or $lasthour2 = time() - 3600; ?> Ken Link to comment https://forums.phpfreaks.com/topic/41644-working-with-dates-and-times/#findComment-201831 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.