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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Function to convert hours and minutes to seconds

Author  Topic 

agnesvictoria
Starting Member

3 Posts

Posted - 2007-09-05 : 01:32:28
Hi everyone,

Please tell me is there any function to convert the given time format hh:mm:ss into seconds.

I have got one of the solutions as

(15*3600+23*60+4)/86400

Thanks in advance.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-09-05 : 01:35:15
the given time is in datatime data type or string ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2007-09-05 : 01:37:29
select datediff(s,'09/04/2007',getdate())
Go to Top of Page

agnesvictoria
Starting Member

3 Posts

Posted - 2007-09-05 : 01:38:03
quote:
Originally posted by khtan

the given time is in datatime data type or string ?


KH
[spoiler]Time is always against us[/spoiler]





It is a string value.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-09-05 : 01:38:21
[code]DECLARE @timestr varchar(10),
@time datetime

SELECT @timestr = '12:34:56',
@time = '12:34:56'

SELECT DATEDIFF(second, 0, @timestr),
DATEDIFF(second, 0, @time)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

agnesvictoria
Starting Member

3 Posts

Posted - 2007-09-05 : 02:09:38
quote:
Originally posted by khtan

DECLARE @timestr varchar(10),
@time datetime

SELECT @timestr = '12:34:56',
@time = '12:34:56'

SELECT DATEDIFF(second, 0, @timestr),
DATEDIFF(second, 0, @time)



KH
[spoiler]Time is always against us[/spoiler]





Thanks alot.
Go to Top of Page
   

- Advertisement -