getting timestamp of hour

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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

getting timestamp of hour

Post by s.dot »

Say I have an hour in the format of 0-23.. date("G");
And let's say that evaluated to 16 (4:00 pm)

How do I get the timestamp of the current day at 4:00 pm
This could be ran on any day, so I don't like putting "Aug 17", but I'm just trying to get something that works.

I've tried

Code: Select all

$hour = date("G");
echo strtotime(date("Aug 17th $hour", time()));
But it doesn't seem to be working =/
Seems so simple but I can't get it.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

Hmm the date format:

Code: Select all

date("Aug 17th $hour", time())
is quite illegal, see the date function on php.net.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

superdezign wrote:mktime().
Ah, that's the function I'm looking for.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

miro_igov wrote:Hmm the date format:

Code: Select all

date("Aug 17th $hour", time())
is quite illegal, see the date function on php.net.
Yeah, I don't even know what I was thinking. :?:
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

How come these don't produce the same timestamp?

Code: Select all

C:\Users\HP_Administrator>php -r "echo mktime(date('G'));"
1187386501

C:\Users\HP_Administrator>php -r "echo strtotime('Aug 17 17:00');"
1187384400
In fact, they're 2101 seconds apart (35.016 minutes). Does mktime(date('G')) take into account the minutes and seconds of the hour as well? (I did do this around 17:35 PM or.. 5:35).

I need it to mktime() of date('G') at 00 minutes and 00 seconds.

[edit] Nevermind, this is my feelstupid moment for the day. And I need to learn to RTFM.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

mktime accepts 6 interegr parameters - hour,min,sec, day,month,year.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

scottayy wrote:[edit] Nevermind, this is my feelstupid moment for the day. And I need to learn to RTFM.
I think he figured it out, miro. ;)
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

From scottayy's posts counter i see he is experienced, how is possible to do such a mistakes?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

miro_igov wrote:From scottayy's posts counter i see he is experienced, how is possible to do such a mistakes?
He just didn't look at the full documentation. The mistake was that he did this:

Code: Select all

mktime(date('G'));
When he meant to do this:

Code: Select all

mktime(date('G'), 0, 0);
Post Reply