Jump to content

[SOLVED] Timeframe


timmah1

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.