Jump to content

check if its one hour before time


a.mlw.walker

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/255489-check-if-its-one-hour-before-time/
Share on other sites

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";
}

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.

 

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.