Dates - back to basics.

This is a discussion on Dates - back to basics. within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hello .. Occasionaly I realise that I take certain functionality for granted and don't understand it as well as perhaps ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-16-2004
Fabian Hore
 
Posts: n/a
Default Dates - back to basics.

Hello ..

Occasionaly I realise that I take certain functionality for granted and
don't understand it as well as perhaps I should.
This is one of those times.

Regarding the behaviour of integer timestamps -
Can anyone tell me why the full dates returned [below] from two timestamps
have different timezone offsets?

<?php
// the epoch.
echo date('Y-m-d H:i:s O', 0);
// prints "1970-01-01 01:00:00 +0100"
// offset +1 hour

// exactly two years later
echo date('Y-m-d H:i:s O', 63072000);
// prints "1972-01-01 00:00:00 +0000"
// offset 0
?>


This seems pretty fundamental - any help is much appreciated.




Reply With Quote
  #2 (permalink)  
Old 12-16-2004
d
 
Posts: n/a
Default Re: Dates - back to basics.

I don't know what you've done to your computer, but I get:

1970-01-01 00:00:00 +0000

and

1972-01-01 00:00:00 +0000

dave.

"Fabian Hore" <fabianhore@email.com> wrote in message
news:QR4wd.771$qv4.299@newsfe1-win.ntli.net...
> Hello ..
>
> Occasionaly I realise that I take certain functionality for granted and
> don't understand it as well as perhaps I should.
> This is one of those times.
>
> Regarding the behaviour of integer timestamps -
> Can anyone tell me why the full dates returned [below] from two timestamps
> have different timezone offsets?
>
> <?php
> // the epoch.
> echo date('Y-m-d H:i:s O', 0);
> // prints "1970-01-01 01:00:00 +0100"
> // offset +1 hour
>
> // exactly two years later
> echo date('Y-m-d H:i:s O', 63072000);
> // prints "1972-01-01 00:00:00 +0000"
> // offset 0
> ?>
>
>
> This seems pretty fundamental - any help is much appreciated.
>
>
>
>



Reply With Quote
  #3 (permalink)  
Old 12-16-2004
Andy Hassall
 
Posts: n/a
Default Re: Dates - back to basics.

On Thu, 16 Dec 2004 00:42:24 GMT, "Fabian Hore" <fabianhore@email.com> wrote:

>Occasionaly I realise that I take certain functionality for granted and
>don't understand it as well as perhaps I should.
>This is one of those times.
>
>Regarding the behaviour of integer timestamps -
>Can anyone tell me why the full dates returned [below] from two timestamps
>have different timezone offsets?
>
><?php
>// the epoch.
>echo date('Y-m-d H:i:s O', 0);
>// prints "1970-01-01 01:00:00 +0100"
>// offset +1 hour
>
>// exactly two years later
>echo date('Y-m-d H:i:s O', 63072000);
>// prints "1972-01-01 00:00:00 +0000"
>// offset 0
>?>
>
>
>This seems pretty fundamental - any help is much appreciated.


Searching on Google finds that the above result is in fact correct. From 1968
to 1972, the UK didn't change the clocks in winter.

http://wwp.greenwichmeantime.com/inf...ightsaving.htm

If you want to stick to GMT/UTC, you probably want to use gmdate().

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Reply With Quote
  #4 (permalink)  
Old 12-16-2004
Fabian Hore
 
Posts: n/a
Default Re: Dates - back to basics.

>> Searching on Google finds that the above result is in fact correct. From
1968
>> to 1972, the UK didn't change the clocks in winter.


Perfect. as long as I know why, I can sleep at night.
thanks






Reply With Quote
  #5 (permalink)  
Old 12-17-2004
d
 
Posts: n/a
Default Re: Dates - back to basics.

But what about the fact that it doesn't do it all the time? On my machine,
both of your examples yielded the expected result - both +0000...

"Fabian Hore" <fabianhore@email.com> wrote in message
news:xtmwd.1385$Fz4.1155@newsfe4-gui.ntli.net...
>>> Searching on Google finds that the above result is in fact correct. From

> 1968
>>> to 1972, the UK didn't change the clocks in winter.

>
> Perfect. as long as I know why, I can sleep at night.
> thanks
>
>
>
>
>
>



Reply With Quote
  #6 (permalink)  
Old 12-17-2004
Hilarion
 
Posts: n/a
Default Re: Dates - back to basics.

> But what about the fact that it doesn't do it all the time? On my machine, both of your examples yielded the expected result -
> both +0000...


It depends on timezone settings on your system, which is used by "date"
function (and other time manipulation functions).

Hilarion


Reply With Quote
  #7 (permalink)  
Old 12-17-2004
Andy Hassall
 
Posts: n/a
Default Re: Dates - back to basics.

On Fri, 17 Dec 2004 11:32:09 GMT, "d" <d@example.com> wrote:

>But what about the fact that it doesn't do it all the time? On my machine,
>both of your examples yielded the expected result - both +0000...


Timezone settings.

andyh@server:~/tmp$ echo $TZ
Europe/London

andyh@server:~/tmp$ php -q tz.php
1970-01-01 01:00:00 +0100
1972-01-01 00:00:00 +0000

andyh@server:~/tmp$ TZ=UTC php -q tz.php
1970-01-01 00:00:00 +0000
1972-01-01 00:00:00 +0000

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Reply With Quote
  #8 (permalink)  
Old 12-18-2004
Fabian Hore
 
Posts: n/a
Default Re: Dates - back to basics.

"d" <d@example.com> wrote in message
news:Zszwd.416$Qo4.13@fe1.news.blueyonder.co.uk...
> But what about the fact that it doesn't do it all the time? On my

machine,
> both of your examples yielded the expected result - both +0000...
>


Adding the `T' token into your date format string shows whats going on.
<?php
echo "\n", date('Y-m-d H:i:s TO', 0); // "1970-01-01 01:00:00
BST+0100"
echo "\n", date('Y-m-d H:i:s TO', 63072000); // "1972-01-01 00:00:00
GMT+0000"
?>

This makes sense of Andy's first reply regarding the UK's clock changing
nuance.

On my system, the date() function is automatically selecting between British
Summer Time and Greenwich Mean Time.
I'd rather it didn't, so I guess there's a lesson here, Don't be flippant
with timestamps. they're handy and portable but not without their caveats.


A appropriate warning appears in the PHP docs in reference to the mktime()
func.
<<
This can be more reliable than simply adding or subtracting the number of
seconds in a day or month to a timestamp because of daylight savings time.
>>








Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:56 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0