Ok, so, to set the time 3 hours in the future, I think I have to use the mktime() function… which, for some reason, seems more confusing than it should be. I probably pass date("h")+3 as one of the arguments, right?
Anybody have a clue?
Ok, so, to set the time 3 hours in the future, I think I have to use the mktime() function… which, for some reason, seems more confusing than it should be. I probably pass date("h")+3 as one of the arguments, right?
Anybody have a clue?
Tags: Code Monkey, PHP
You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.
Being Amber Rhea is somewhat incredulously powered by WordPress
11 Responses to "That pesky timestamp"
If you have root access, why not reset the timezone with tzselect or tzconfig?
date() will prolly have edge cases where it breaks, like daylight savings time coming in and out.
Will
I’m sure you are turning nerds on everywhere with this question. However, you are just making my head hurt, bwana.
Meant to tell you I like the hair. I’m getting mine done manana, but not by a fabulous gay man. If only we were all so lucky…
I don’t have root access, that’s why I’m asking. I’ve moved from my own server in my bedroom, to a DreamHost account.
Well, I am really annoyed. I tried messing with the
mktime()function but no luck. I think it might have to do with the fact that something is getting messed up when it tries to do the insert into the database, because the column type isdatetime. Anyway, hopefully tomorrow Chris will play “debugger” for me and we can get this figured out. :)Or we could all show some initiative and just add (typo:ass) three hours to the time stamps. Not really satisfying to your J-preference, I know, but…
Niki you know that is driving Amber crazy to have this anomaly on her web page. It will be squashed.
That’s right! Chris, I haven’t had time yet to try your code, but I will as soon as I have a free moment. And Niki… what, you want me to make my readers think? That’s crazy talk!
I know it’s driving you crazy, because, like me, you like to have things perfect. That’s why I suggested you leave it: because I knew you wouldn’t. >:)
m@ber, you’re not alone, it would drive me bonkers as well. wanna make it a project once you have it figured out? have another setting that gets persisted on a per user basis that allows them to select a time zone. so they can see times relative to where they are. :) sorry, if you weren’t looking for more ideas, then just ignore me. :)
It isn’t exactly clear what you are looking for, but mktime() may not be the right function for you.
Unix systems measure time in seconds it’s been since January 1st, 1970, at 00:00.
To get the current time, in seconds from epoch, do something like this:
$time = time();
print “$time”;
This should return some big number like this: 1111453817.
Now to go three hours in the future you just add 10800 seconds:
$time = $time + 10800;
This obviously won’t be human readable, so I’d suggest formating it with the date() function.
The date() function can take the seconds from epoch and format it for you, like this:
$date = date(”m/d/y, h:i A”,$time);
print “$date”
That should return something like this: 03/21/05, 08:10 PM
The mktime function, on the other hand takes a specific date and time and gives you the seconds for epoch for that point in time.
For instance, say you wanted to know the exact seconds from epoch for 8:15:01 PM, March 24, 2005. (under daylight savings, and note that the hour is on a 24 hour clock) You could:
$time = mktime(20, 15, 1, 3, 24, 2005, 1);
print “$time”;
this would print something like: 1111453817.
Um, I cut and pasted the wrong number at the end there, that specific date and time, at the end, would be 1111720501, not 1111453817.