Convert Time to Second in MySql


One day i had a little problem with my office work. Report that we made not in accordance with user, one of them, report has time value with standard format : hh : mm : ss but user want a value in number like 1,5 hour for 1:30:00. Solution of this situation, we can use time_to_sec() function in mysql. TIME_TO_SEC( ) converts a TIME value to the equivalent number of seconds, and SEC_TO_TIME( ) does the opposite. The following query demonstrates a simple conversion in both directions:

1. First you need to create a mysql table with a time type : 
CREATE TABLE coba( no int(10), time time);
INSERT INTO coba VALUES('1', '1:30:30');






SELECT * FROM coba;






2. Convert to second value
SELECT no, TIME_TO_SEC(time)/3600 as ' Time in New Value' FROM coba;





3. Finish.