tags:

views:

55

answers:

1

Hello all,

I have confused myself to a point where I need to double check this with you all. Sorry if this is really a dumb question..

Okay - I have a PHP web application running on Linux that needs to support timezones. I provide a calendar widget that allows the user to set their timezone then select the date and hours/minutes for some event.

I then store that value in a record as an int by using. When I need to show the date again to the user I just get their timezone setting and apply to the int value.

Code:

$dtzone = new DateTimeZone($time_zone);
$dtime = new DateTime($date_time, $dtzone);
$timestamp = $dtime->format('U');
return $timestamp;

Notes: $date_time comes in this format 'YYYY-MM-DD H:S' $time_zone is what they selected eg: America/Jamaica

Now I store the int returned in the database.

I then have a PHP script that I execute via CRON which runs within a server in Sydney - Australia.

My understanding is that all my script needs to do is get the servers current time stamp via time() then search the database for any integers with the exact same integer produced by the time() call. I don't have to worry about what timezone the user used to select the date/time.

Note that the CRON must run every minute as I allowed the user to select the minute as well.

Is this assumption correct?

Cheers

Marc

+1  A: 

If you're storing the timestamps as int then you're most likely using unix timestamps which are always UTC. A unix timestamp is the same no matter where it is generated. Be it Jamaica, Sydney, or Mars.

Mike B
Thanks Mike - it gets confusing with all the talk about UTC, GMT and offsets. I thought that we all use the same "time stream" from the magic 1970 Unix time-set so when a time gets converted to an int using that code then it represents an exact point in time that we all share.
zanis
That's precisely what a unix timestamp represents. UTC represents the 'coordinated universal time' which all timezones alter (i.e. Etc/GMT-5). UTC is the foundation and thus the most appropriate time-standard for unix timestamps.
Mike B
Hello again,I was wondering if anyone knows how to deal with the following - continuing on with my timestamp saga.When the timestamp of the users selected date/hour/minute is saved to the database the seconds are set at 00 - I assume 00 as when I convert the timestamp back to date format the seconds are '00'.Thus I can have a timestamp of 1262746260.Looking at the linux cron logs I can see the CRON actually runs at 1 sec after the minute. So when the current timestamp is generated on the server for the compare search the integer can be at least 1 second off ..
zanis
thus it never finds any timestamp matches!Is there a format for mySQL that states something like this:"Find all records with the timestamp of 'timestamp' within the say 10 seconds"This will allow my CRON to locate records even though the timestamp generated for the search is not exactly at 1 minute and zero seconds.
zanis
MySQL's BETWEEN operator may be able to help. You may also want to create another question for this.
Mike B