[PHP] Time zones are spinning my brain
Help. I'm using PayPal's API to get a report of all the yesterday's transactions. I'm in California, and I define "yesterday" as California's yesterday, midnight to midnight. PayPal wants the STARTDATE and ENDDATE provided in UTC/GMT. I'm building and testing my report using this: $start = gmdate('Y-m-d\TH:i:s.00\Z', strtotime("yesterday 00:00:00")); $end = gmdate('Y-m-d\TH:i:s.00\Z', strtotime("yesterday 23:59:59")); which produces: 2011-06-28T07:00:00.00Z 2011-06-29T06:59:59.00Z I think this is right, since it's 7 hours off California time, but I just need someone to double check my spinning head. Will this give me the PayPal transactions that arrived during California's yesterday, or do I need to change something? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Time zones are spinning my brain
On 29 June 2011 17:09, Brian Dunning wrote: > Help. I'm using PayPal's API to get a report of all the yesterday's > transactions. I'm in California, and I define "yesterday" as California's > yesterday, midnight to midnight. > > PayPal wants the STARTDATE and ENDDATE provided in UTC/GMT. I'm building and > testing my report using this: > > $start = gmdate('Y-m-d\TH:i:s.00\Z', strtotime("yesterday 00:00:00")); > $end = gmdate('Y-m-d\TH:i:s.00\Z', strtotime("yesterday 23:59:59")); > > which produces: > > 2011-06-28T07:00:00.00Z > 2011-06-29T06:59:59.00Z > > I think this is right, since it's 7 hours off California time, but I just > need someone to double check my spinning head. Will this give me the PayPal > transactions that arrived during California's yesterday, or do I need to > change something? > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Something like this ? getTimestamp()), ' to ', date('Y-m-d\TH:i:s.99\Z', $o_End->getTimestamp()), PHP_EOL; And UTC is not the same as GMT. Ish. GMT is only valid for 6 months of the year. Then, due to DST, it becomes BST. UTC is just UTC. Also, your DST may not be on the same day as GMT->BST. Using the timezone America/Los_Angeles holds all the various shifts in DST and offset that have been recorded, so you can use current local time (shifted with DST just like you would read off your watch of PC) with that timezone and PHP can work out what the timestamp is. It sounds a little messy, but the TLA timezones aren't always sufficient. Derick did a really good talk about this a couple of years ago for php|Architect. I'm sure there's a video somewhere of it. All makes perfect sense in the end. -- Richard Quadling Twitter : EE : Zend : PHPDoc @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Time zones are spinning my brain
On Wed, 29 Jun 2011, Brian Dunning wrote: $start = gmdate('Y-m-d\TH:i:s.00\Z', strtotime("yesterday 00:00:00")); $end = gmdate('Y-m-d\TH:i:s.00\Z', strtotime("yesterday 23:59:59")); I think this is right, since it's 7 hours off California time, but I just need someone to double check my spinning head. Will this give me the PayPal transactions that arrived during California's yesterday, or do I need to change something? Assuming your timezone is set to California time ( date_default_timezone_set ('America/Los_Angeles') ), then yes. Geoff. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Time zones are spinning my brain
On Wed, 29 Jun 2011, Richard Quadling wrote: And UTC is not the same as GMT. Ish. GMT is only valid for 6 months of the year. Then, due to DST, it becomes BST. UTC is just UTC. This is incorrect. For all practical purposes, GMT and UTC are the same. The fact that the time in Greenwich is not GMT/UTC for half the year is not relevant. http://www.diffen.com/difference/GMT_vs_UTC All the GM* functions (gmdate, gmstrftime, etc) are intended for dealing with Universal Co-ordinated Time. As a side note, there is (or at least was) no gmstrtotime function. I get around this by putting " +" at the end of the string. HTH, Geoff. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Time zones are spinning my brain
Thanks everyone. It seems to be working correctly. You gave me some extra peace of mind. I did set the date_default_timezone_set('America/Los_Angeles') but it looks like that was in the defaults anyway. :-) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Time zones are spinning my brain
On Wed, 29 Jun 2011, Brian Dunning wrote: Thanks everyone. It seems to be working correctly. You gave me some extra peace of mind. I did set the date_default_timezone_set('America/Los_Angeles') but it looks like that was in the defaults anyway. :-) It probably is if this is where your site is hosted. But all you need to do is change hosting providers to one somewhere else, or for someone who's not careful to mess something up on the system, and the script will break all because you assumed it would always be right. So better to set it and know it's right. Geoff. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] Time zones are spinning my brain
On 29 Jun 2011 at 17:25, Richard Quadling wrote: > And UTC is not the same as GMT. Ish. Yes it is. > GMT is only valid for 6 months of the year. Then, due to DST, it becomes BST. No, the UK is on GMT for 5 months a year and then on BST (GMT+1) for 7 months. -- Cheers -- Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php