liomon41 Posted June 10, 2012 Share Posted June 10, 2012 I trying to write a code in php that they tells the user that they've got 1 hour before a specific time is reached... Quote Link to comment https://forums.phpfreaks.com/topic/263934-time-in-php/ Share on other sites More sharing options...
cpd Posted June 10, 2012 Share Posted June 10, 2012 Awesome... what's the problem? Quote Link to comment https://forums.phpfreaks.com/topic/263934-time-in-php/#findComment-1352593 Share on other sites More sharing options...
liomon41 Posted June 10, 2012 Author Share Posted June 10, 2012 I have a program that stores date and time for future events in the database, upon retrieving this information from the database, I'd like to know how to write a code to check if the current time is 1 hour prior to the time in the database.... any ideas.. Quote Link to comment https://forums.phpfreaks.com/topic/263934-time-in-php/#findComment-1352596 Share on other sites More sharing options...
Barand Posted June 10, 2012 Share Posted June 10, 2012 strtotime() will convert the db datetime to unix time (seconds) time() will give current unix time. Quote Link to comment https://forums.phpfreaks.com/topic/263934-time-in-php/#findComment-1352599 Share on other sites More sharing options...
cpd Posted June 10, 2012 Share Posted June 10, 2012 $timeMinus1Hour = gmdate("Y-m-d H:i:s", strtotime("-1 hour", strtotime($time))); Where $time is the date/time timestamp from the database. Bare in mind time-zones; I did that using Greenwich Mean Time. A simple comparison of the two timestamps will give you your answer. Quote Link to comment https://forums.phpfreaks.com/topic/263934-time-in-php/#findComment-1352600 Share on other sites More sharing options...
liomon41 Posted June 10, 2012 Author Share Posted June 10, 2012 I'm sorry, im kinda new to this part of php, how do you compare the timestamp..... ??? Quote Link to comment https://forums.phpfreaks.com/topic/263934-time-in-php/#findComment-1352605 Share on other sites More sharing options...
Barand Posted June 10, 2012 Share Posted June 10, 2012 http://us2.php.net/manual/en/language.operators.comparison.php Quote Link to comment https://forums.phpfreaks.com/topic/263934-time-in-php/#findComment-1352608 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.