dbTalk Databases Forums  

unix_timestamp wrong by one hour for 1970

comp.databases.mysql comp.databases.mysql


Discuss unix_timestamp wrong by one hour for 1970 in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Udo Grabowski
 
Posts: n/a

Default unix_timestamp wrong by one hour for 1970 - 04-14-2011 , 04:45 AM






Look at this (mysql 5.1.30 solaris x86-64):

mysql> select unix_timestamp('1970-01-02 00:00:00')-
unix_timestamp('1970-01-01 00:00:00');
+-----------------------------------------------------------------------------+
Quote:
unix_timestamp('1970-01-02 00:00:00')-unix_timestamp('1970-01-01 00:00:00') |
+-----------------------------------------------------------------------------+
82800 |
+-----------------------------------------------------------------------------+

mysql> select unix_timestamp('1970-01-03 00:00:00')-
unix_timestamp('1970-01-02 00:00:00');
+-----------------------------------------------------------------------------+
Quote:
unix_timestamp('1970-01-03 00:00:00')-unix_timestamp('1970-01-02 00:00:00') |
+-----------------------------------------------------------------------------+
86400 |
+-----------------------------------------------------------------------------+

mysql> select unix_timestamp('1970-01-02 00:00:00');
+---------------------------------------+
Quote:
unix_timestamp('1970-01-02 00:00:00') |
+---------------------------------------+
82800 |
+---------------------------------------+

mysql> select unix_timestamp('1970-01-01 01:00:00');
+---------------------------------------+
Quote:
unix_timestamp('1970-01-01 01:00:00') |
+---------------------------------------+
0 |
+---------------------------------------+

Where the heck is the first hour ??? All unix_timestamps are wrong
by this mysterious hour, so unix_timestamp is the number
of seconds since '1970-01-01 01:00:00', not '1970-01-01 00:00:00', as
all MySQL documents are pretending:
" If UNIX_TIMESTAMP() is called with a date argument, it returns
the value of the argument as seconds since '1970-01-01 00:00:00' UTC. "
This is simply not true.

Reply With Quote
  #2  
Old   
Jerry Stuckle
 
Posts: n/a

Default Re: unix_timestamp wrong by one hour for 1970 - 04-14-2011 , 05:17 AM






On 4/14/2011 5:45 AM, Udo Grabowski wrote:
Quote:
Look at this (mysql 5.1.30 solaris x86-64):

mysql> select unix_timestamp('1970-01-02 00:00:00')-
unix_timestamp('1970-01-01 00:00:00');
+-----------------------------------------------------------------------------+

| unix_timestamp('1970-01-02 00:00:00')-unix_timestamp('1970-01-01
00:00:00') |
+-----------------------------------------------------------------------------+

| 82800 |
+-----------------------------------------------------------------------------+


mysql> select unix_timestamp('1970-01-03 00:00:00')-
unix_timestamp('1970-01-02 00:00:00');
+-----------------------------------------------------------------------------+

| unix_timestamp('1970-01-03 00:00:00')-unix_timestamp('1970-01-02
00:00:00') |
+-----------------------------------------------------------------------------+

| 86400 |
+-----------------------------------------------------------------------------+


mysql> select unix_timestamp('1970-01-02 00:00:00');
+---------------------------------------+
| unix_timestamp('1970-01-02 00:00:00') |
+---------------------------------------+
| 82800 |
+---------------------------------------+

mysql> select unix_timestamp('1970-01-01 01:00:00');
+---------------------------------------+
| unix_timestamp('1970-01-01 01:00:00') |
+---------------------------------------+
| 0 |
+---------------------------------------+

Where the heck is the first hour ??? All unix_timestamps are wrong
by this mysterious hour, so unix_timestamp is the number
of seconds since '1970-01-01 01:00:00', not '1970-01-01 00:00:00', as
all MySQL documents are pretending:
" If UNIX_TIMESTAMP() is called with a date argument, it returns
the value of the argument as seconds since '1970-01-01 00:00:00' UTC. "
This is simply not true.
Because your system's timezone is set to UTC-1 currently.

The manual is correct and matches UNIX's clock.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex (AT) attglobal (DOT) net
==================

Reply With Quote
  #3  
Old   
Udo Grabowski
 
Posts: n/a

Default Re: unix_timestamp wrong by one hour for 1970 - 04-14-2011 , 06:00 AM



Jerry Stuckle wrote:
Quote:
Because your system's timezone is set to UTC-1 currently.

The manual is correct and matches UNIX's clock.

No, it's set to UTC+1 + DST, but this shouldn't affect
the very first hour in 1970.

Reply With Quote
  #4  
Old   
Udo Grabowski
 
Posts: n/a

Default Re: unix_timestamp wrong by one hour for 1970 - 04-14-2011 , 06:26 AM



Udo Grabowski wrote:
Quote:
Jerry Stuckle wrote:

Because your system's timezone is set to UTC-1 currently.

The manual is correct and matches UNIX's clock.


No, it's set to UTC+1 + DST, but this shouldn't affect
the very first hour in 1970.
Ok, I see the kludge: 1970-01-01 00:00:00 UTC IS 1970-01-01 01:00:00
in my timezone, so that's actually my zeropoint for unix_timestamp(),
since unix_timestamp is TZ dependent. Tricky.

Reply With Quote
  #5  
Old   
Axel Schwenke
 
Posts: n/a

Default Re: unix_timestamp wrong by one hour for 1970 - 04-14-2011 , 07:25 AM



Udo Grabowski <udo.grabowski (AT) imk (DOT) fzk.REMOVEJUNK.de> wrote:

Quote:
Because your system's timezone is set to UTC-1 currently.

Ok, I see the kludge: 1970-01-01 00:00:00 UTC IS 1970-01-01 01:00:00
in my timezone, so that's actually my zeropoint for unix_timestamp(),
since unix_timestamp is TZ dependent. Tricky.
It's nothing to do with the unix_timestamp() function. But
'1970-01-02 00:00:00' is a DATETIME literal and as such it
implicitly uses your local time zone.

If you want to give DATETIME literals in UTC, you must convert
them to your local timezone before putting them into expressions


mysql> show global variables like '%time_zone';
+------------------+--------+
Quote:
Variable_name | Value |
+------------------+--------+
system_time_zone | CEST |
time_zone | SYSTEM |
+------------------+--------+
2 rows in set (0,00 sec)

mysql> select convert_tz('1970-01-02 00:00:00', @@time_zone, 'GMT');
+-------------------------------------------------------+
Quote:
convert_tz('1970-01-02 00:00:00', @@time_zone, 'GMT') |
+-------------------------------------------------------+
1970-01-01 23:00:00 |
+-------------------------------------------------------+
1 row in set (0,00 sec)

mysql> select unix_timestamp(convert_tz('1970-01-02 00:00:00', 'GMT', @@time_zone))
-unix_timestamp(convert_tz('1970-01-01 00:00:00', 'GMT', @@time_zone)) as x;
+-------+
Quote:
x |
+-------+
86400 |
+-------+
1 row in set (0,00 sec)


Still I think you found a bug. '1970-01-01 00:00:00 MEST' is an
invalid argument for the unix_timestamp() function, because it
is out of range. This expression should give a warning, and in
strict mode even an error.


XL

Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.