Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Change a time format from 00:00:00 into seconds

Author  Topic 

PHenry
Starting Member

10 Posts

Posted - 2012-04-18 : 18:30:39
One of the columns in a table is called productDelivered which uses the data type time(7); however, i would like to convert the time to seconds and keep it. I have around 50-60 records.

Is there a way to change these times to seconds? I dont mind creating a new column in the table for productDeliveredSeconds but I thought maybe a stored procedure or a view might do it?

The following was suggested but since new to the SQL language i dont actually understand how that relates with my column productDelivered and where the seconds are outputted to?

TIME_TO_SEC(time)

Returns the time argument, converted to seconds.

mysql> SELECT TIME_TO_SEC('22:23:00');
-> 80580
mysql> SELECT TIME_TO_SEC('00:39:38');
-> 2378

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-04-18 : 18:36:45
Looks like you aren't using Microsoft SQL Server, so I would suggest posting on a site that specializes in your technology. SQLTeam.com is for MSSQL only.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

PHenry
Starting Member

10 Posts

Posted - 2012-04-18 : 18:44:42
Its still just MySql though within the programming environment, this is why i thought it was suitable.

quote:
Originally posted by tkizer

Looks like you aren't using Microsoft SQL Server, so I would suggest posting on a site that specializes in your technology. SQLTeam.com is for MSSQL only.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-04-18 : 18:46:10
It matters because TIME_TO_SEC isn't valid in MSSQL. We can provide a solution for MSSQL, but it may not work in MySql.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-04-18 : 18:54:20
SELECT DATEDIFF(SECOND, '00:00:00', '22:23:00');



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

PHenry
Starting Member

10 Posts

Posted - 2012-04-19 : 03:35:14
Could you explain how this works please?

quote:
Originally posted by SwePeso

SELECT DATEDIFF(SECOND, '00:00:00', '22:23:00');



N 56°04'39.26"
E 12°55'05.63"


Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-04-19 : 12:29:55
Does MySql have the DATEDIFF function? It's a date difference function. Because Peter is putting SECOND as the first parameter, it's doing the comparison in seconds. So you are getting exactly what you want.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-19 : 14:16:42
it has but with different definition

http://www.w3schools.com/sql/func_datediff_mysql.asp

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -