$ mysql --version mysql Ver 14.14 Distrib 5.1.58, for debian-linux-gnu (x86_64) using readline 6.2
で、ログインしてやってみた。
$ mysql -u root -p mysql> select from_unixtime(unix_timestamp('1970-01-01 00:00:00')) from dual; +------------------------------------------------------+ | from_unixtime(unix_timestamp('1970-01-01 00:00:00')) | +------------------------------------------------------+ | 1970-01-01 09:00:00 | +------------------------------------------------------+ 1 row in set (0.00 sec) mysql> select from_unixtime(unix_timestamp('1970-01-01 09:00:00')) from dual; +------------------------------------------------------+ | from_unixtime(unix_timestamp('1970-01-01 09:00:00')) | +------------------------------------------------------+ | 1970-01-01 09:00:00 | +------------------------------------------------------+ 1 row in set (0.01 sec)
ん?1970-01-01 00:00:00 も 1970-01-01 09:00:00 も結果は同じ?
ちょっと待て。
mysql> select unix_timestamp('1970-01-01 00:00:00') from dual; +---------------------------------------+ | unix_timestamp('1970-01-01 00:00:00') | +---------------------------------------+ | 0 | +---------------------------------------+ 1 row in set (0.00 sec) mysql> select unix_timestamp('1970-01-01 09:00:00') from dual; +---------------------------------------+ | unix_timestamp('1970-01-01 09:00:00') | +---------------------------------------+ | 0 | +---------------------------------------+ 1 row in set (0.01 sec)
両方とも「0」かよ。
じゃこれはどうかな?
mysql> select from_unixtime(0) from dual; +---------------------+ | from_unixtime(0) | +---------------------+ | 1970-01-01 09:00:00 | +---------------------+ 1 row in set (0.00 sec)
マニュアルはどうなってる?
>UNIX_TIMESTAMP() に範囲外の日付を渡すと、0 が戻されます。
あぁ、そういうことね。1970-01-01 00:00:00 は「範囲外」ってことね。
納得。
0 件のコメント:
コメントを投稿