View Single Post

  #2 (permalink)  
Old 02-28-2008
Rik Wasmus
 
Posts: n/a
Default Re: Why TimeStamp was truncated?

On Thu, 28 Feb 2008 11:43:18 +0100, howa <howachen@gmail.com> wrote:

> CREATE TABLE `table1` (
> `ts` TIMESTAMP NOT NULL
> ) ENGINE = innodb;
>
> INSERT INTO `table1` (`ts`) VALUES ('1202832067');
> INSERT INTO `table1` (`ts`) VALUES ( UNIX_TIMESTAMP('1202832067') );
>
> The table result is storing "0000-00-00 00:00:00" for both queries,
> any idea?


Because MySQL doesn't automatically convert an integer to a datetime
string.
INSERT INTO `table1` (`ts`) VALUES ( FROM_UNIXTIME('1202832067') );
--
Rik Wasmus
Reply With Quote