Convert current time and ANY time - how?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Convert current time and ANY time - how?

Post by simonmlewis »

Code: Select all

echo gettimeofday(true);
This seems to extract the time on the server into a PHP string.
How do you state a given time, and then convert that into a PHP string so it cna be queried?

For example. I want a button to appear only before 5pm. at 17:01 I want that button to disappear.
I theory I'd say:
get current time.
setQueryTime to 17:00.
If currentTime is <= QueryTime, then show button.
Else, do not show button.

That's basically it. Doing all that with a date is a doddle. But how do you do it with time??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
jaceinla
Forum Commoner
Posts: 25
Joined: Thu Oct 14, 2010 12:57 pm

Re: Convert current time and ANY time - how?

Post by jaceinla »

Code: Select all

if(17 >= date('H'))   //returns hour on a 24 clock
{
   //do not show button
}
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Convert current time and ANY time - how?

Post by simonmlewis »

Reading your code (which looks unbelievably simple), I think it says:

if '17' is less than (or =) the current hour, then do this, if it is more than (or =) the current hour, then do that.

Man I was expecting some long-winded code, but that is geniuuuuus. So thank you.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply