datetime - Why do I get NULL results with the MySQL function TIME_TO_SEC? -
i have mysql table 2 datetime columns. want create 1 new generated column contains time difference of 2 datetime columns. using mysql function time_to_sec
convert difference seconds.
strangely of rows return null, , unable understand why. here first 25 rows of table..
class_session_id starts_on ends_on session_time_computed 8 2014-12-24 03:35:47 2014-12-24 05:07:33 na 9 2014-12-24 05:50:37 2014-12-24 07:10:07 na 10 2014-12-24 07:18:51 2014-12-24 08:52:27 na 11 2014-12-19 09:00:41 2014-12-19 10:35:54 5713 12 2014-12-19 10:45:29 2014-12-19 11:55:48 4219 13 2014-12-24 12:00:00 2014-12-24 14:00:00 7200 14 2014-12-24 14:32:10 2014-12-24 14:47:18 908 15 2014-12-24 14:48:13 2014-12-25 08:29:51 na 16 2014-12-15 04:06:13 2014-12-15 04:20:41 868 17 2014-12-15 07:09:27 2014-12-15 08:20:40 4273 18 2014-12-15 06:42:28 2014-12-15 06:51:43 555 28 2014-11-25 11:18:00 2014-11-25 09:30:00 na 29 2014-11-27 10:18:00 2014-11-27 11:30:00 4320 30 2014-11-26 08:18:00 2014-11-26 09:30:00 4320 34 2015-01-08 10:41:52 2015-01-08 11:00:00 3528 37 2014-12-02 12:44:36 2014-12-02 14:44:00 na 49 2014-11-02 12:44:00 2014-11-02 14:44:00 7200 54 2014-12-07 07:05:35 2014-12-07 07:50:00 na 55 2014-12-07 10:00:00 2014-12-07 11:00:00 3600 56 2014-11-12 12:57:00 2014-11-12 17:00:00 16980 82 2014-12-05 14:29:18 2014-12-05 16:00:00 na 83 2014-12-05 16:29:18 2014-12-05 17:00:00 na 84 2014-12-05 17:49:17 2014-12-05 18:25:00 na 85 2014-12-06 15:00:17 2014-12-06 16:00:00 na 87 2014-12-06 16:25:00 2014-12-06 16:59:00 2040`
i use following script generate last column.
alter table class_sessions_archive modify column session_time_computed int(11) (time_to_sec(ends_on - starts_on));
why null results many rows? here structure of table :
field type null key default class_session_id int(11) no pri <na> auto_increment class_id int(11) no mul <na> room_id int(11) no mul <na> teacher_id int(11) no mul <na> starts_on datetime no <na> ends_on datetime no <na> session_state int(11) no mul <na> stud_attended int(100) yes <na> total_stud_registered int(11) no 0 session_time int(11) no 0 gi_num int(11) no 0 gi_den int(11) no 0 pi int(11) no 0 session_time_computed int(11) yes <na> virtual generated
now think it, convert time seconds before subtracting:
alter table class_sessions_archive modify column session_time_computed int(11) (to_seconds(ends_on) - to_seconds(starts_on));
otherwise, limited range of values time
data type -- why getting null
.
Comments
Post a Comment