2

I am transferring data and updating time formats.

The source data has a timestamp (stored as int(10)) and I am using the following in an attempt to convert to datetime.

INSERT INTO `t2`
SELECT
    t1.type,
    FROM_UNIXTIME(t1.event_time,'%Y-%m-%d %H:%i:%s')
FROM t1;

when running this query the following is encountered...

Error detected in migrationX.sql ( Incorrect datetime value: '2014-07-06T13:00:00Z' for column 'event_date_time' at row 1 [ INSERT INTO `t2`
SELECT
    t1.type,
    FROM_UNIXTIME(t1.event_time,'%Y-%m-%d %H:%i:%s')
FROM t1; ] )

Can anyone suggest a reason as to why the output would contain T and Z characters?

=================

Salient info on table structure...

CREATE TABLE `t1` (
    `t1_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `event_time` int(10) unsigned NOT NULL,
PRIMARY KEY (`t1_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `t2` (
    `t2_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `event_date_time` DATETIME NULL,
PRIMARY KEY (`t2_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

==================

8
  • Do you have a BEFORE INSERT trigger defined on t2?
    – eggyal
    Mar 27, 2015 at 9:32
  • t1.event_time contains this format, you have to check that first Mar 27, 2015 at 9:32
  • Also, please show the output of SHOW CREATE TABLE t2?
    – eggyal
    Mar 27, 2015 at 9:37
  • t1 event time - there are a few million tuples but all contain 10 digits (checked with SELECT * FROM t1 CHAR_LENGTH(event_time) = 10;) I'll add create syntax to OP
    – Ian Wood
    Mar 27, 2015 at 9:45
  • @eggyal There are no triggers involved.
    – Ian Wood
    Mar 27, 2015 at 9:53

1 Answer 1

0
INSERT INTO `t2`
SELECT
    t1.type,
    FROM_UNIXTIME(t1.event_time)
FROM t1;
1
  • While the default would be the format I am requesting I have defined it explicitly just for belt and braces. Unfortunately this has no effect.
    – Ian Wood
    Mar 27, 2015 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.