Page 1 of 1
getting timestamp of hour
Posted: Fri Aug 17, 2007 3:56 pm
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.
Posted: Fri Aug 17, 2007 4:17 pm
by superdezign
Posted: Fri Aug 17, 2007 4:19 pm
by miro_igov
Hmm the date format:
is quite illegal, see the date function on php.net.
Posted: Fri Aug 17, 2007 4:20 pm
by s.dot
Ah, that's the function I'm looking for.
Posted: Fri Aug 17, 2007 4:21 pm
by s.dot
miro_igov wrote:Hmm the date format:
is quite illegal, see the date function on php.net.
Yeah, I don't even know what I was thinking.

Posted: Fri Aug 17, 2007 4:39 pm
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.
Posted: Sat Aug 18, 2007 7:34 am
by miro_igov
mktime accepts 6 interegr parameters - hour,min,sec, day,month,year.
Posted: Sat Aug 18, 2007 9:40 am
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.

Posted: Sat Aug 18, 2007 9:50 am
by miro_igov
From scottayy's posts counter i see he is experienced, how is possible to do such a mistakes?
Posted: Sat Aug 18, 2007 10:02 am
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:
When he meant to do this: