Re: Query based on Server offset TimeStamp
| From: | Philip Thompson | Date: | Tue, 24 Nov 2009 04:13:35 +0000 |
| Subject: | Re: Query based on Server offset TimeStamp | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-300045@lists.php.net to get a copy of this message | ||
On Nov 23, 2009, at 7:37 PM, Don Wieland wrote:
> Hello,
>
> I have a mySQL database server in Florida USA (EST) and I want to do a query on a record in
> California, USA (PST) 3 hours earlier using PST instead of EST.
>
> I would like to add to my CORE page that offset of the timezone so I can use it in a query
> like:
>
> Select * FROM aTable WHERE ServerOffsetTimeStap >= Row_Start_TimeStamp AND
> ServerOffsetTimeStap <= Row_End_TimeStamp
>
> How would I do this?
>
> Appreciate any help you can offer. Thanks!
When I store timestamps, I store them in GMT time. This way, no matter when you pull it out of the
database, you *know* when it was stored - even in a different timezone. To achieve this...
<?php
// Put this into the database
$timeIntoDb = time() - date("Z");
// Pull this from the database
$ts = $timeFromDb + date("Z");
?>
Maybe this will make it a little easier to query accordingly...? Hope this stirs your brain.
~Philip
PS... Others may profess that you use UTC instead of GMT, but that's a different thread.