a.mlw.walker Posted January 21, 2012 Share Posted January 21, 2012 So I am trying to check if the current time is one hour before a variable time: $date_game=$dt->format('Y n j'.$pieces[2]); echo $date_game; echo date('Y n j H'); if (date('Y n j H') < $date_game) { echo "The time is before the stored time"; } This displays 2012 1 21 17:30 2012 1 21 16 i.e $pieces[2] = 17:30. and $dt formatted Y n j = 2012 1 21. The current Y n j H is 2012 1 21 16. I want to know if it is more than one hour until the date/time stored in $date_game. At the moment it just tells me that it is before that time. Can I do something like $data_game - 1->format('H'); or something? Thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/255489-check-if-its-one-hour-before-time/ Share on other sites More sharing options...
Pikachu2000 Posted January 22, 2012 Share Posted January 22, 2012 It looks like you're comparing times that are in UNIX timestamp format, right? Your question isn't completely clear, but is this what you mean? if( time() > $date_game + 3600 ) { echo "it's more than one hour before game"; } Quote Link to comment https://forums.phpfreaks.com/topic/255489-check-if-its-one-hour-before-time/#findComment-1309925 Share on other sites More sharing options...
a.mlw.walker Posted January 22, 2012 Author Share Posted January 22, 2012 so its a plus not a minus! Sorry If I wasnt clear but basically if $dt->format('Y n j') is the same day as today, i.e date('Y n j) and the hour now is the same as my variable $pieces[2], which in this case stated it was half five, (17:30) then I want to run a condition to check whether it is before half four or not on the day that $dt->format('Y n j') states it is. Quote Link to comment https://forums.phpfreaks.com/topic/255489-check-if-its-one-hour-before-time/#findComment-1309927 Share on other sites More sharing options...
SergeiSS Posted January 22, 2012 Share Posted January 22, 2012 You are comparing time as strings - it's not correct. You have to use DateTime object http://ru.php.net/manual/en/book.datetime.php Read about it and about it's diff method. It could be useful in your case Quote Link to comment https://forums.phpfreaks.com/topic/255489-check-if-its-one-hour-before-time/#findComment-1309983 Share on other sites More sharing options...
a.mlw.walker Posted January 22, 2012 Author Share Posted January 22, 2012 Thanks for that link. Incidently, $interval->format('%R%a') == 0 whats %R%a I cant find it on the formatting page? Quote Link to comment https://forums.phpfreaks.com/topic/255489-check-if-its-one-hour-before-time/#findComment-1309991 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.