timmah1 Posted September 17, 2008 Share Posted September 17, 2008 I'm doing a contest script, but the contest can only be played between 4:30pm and 8:00am. I'm not very good with the subtraction and addition of dates and time with PHP, I tried this $start = strtotime('16:30'); $now = time("H:i"); Tells me when to start, and sets the current time And then I have this if($now > $start) { echo "Game cannot be played yet"; } But nothing gets displayed. How do I go about doing this? Thank you in advance Link to comment https://forums.phpfreaks.com/topic/124642-solved-timeframe/ Share on other sites More sharing options...
F1Fan Posted September 17, 2008 Share Posted September 17, 2008 Your problem is that the time() function doesn't use the date codes like "H:i." Try using two timestamps like this: $start = strtotime(date('Y-m-d').' 16:30'); // Be sure you have the date in there, too $now = time(); // Then try an else, so you can test it if($now > $start) { echo "Game cannot be played yet"; } else{ echo "now: $now, start: $start"; } Or something like that. Link to comment https://forums.phpfreaks.com/topic/124642-solved-timeframe/#findComment-643734 Share on other sites More sharing options...
timmah1 Posted September 17, 2008 Author Share Posted September 17, 2008 Thank you F1Fan. Exactly what I needed. I didn't know I had to put the date in there as well. Thanks again! Link to comment https://forums.phpfreaks.com/topic/124642-solved-timeframe/#findComment-643760 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.