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 2012 Forums
 Transact-SQL (2012)
 convert time to number

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2013-06-03 : 09:18:30
declare @duration datetime
select @duration='1900-01-01 00:53:00.000'



I need to know how to convert this so I get the number of minutes

(I want returned 53)

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2013-06-03 : 09:26:54
declare @duration datetime
set @duration='1900-01-01 00:53:00.000'

select
@duration,
datepart(minute,@duration)


Too old to Rock'n'Roll too young to die.
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-06-03 : 09:26:56
declare @duration datetime
select @duration='1900-01-01 00:53:00.000'
SELECT DATEPART(MI, @Duration)

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-03 : 23:59:59
declare @duration datetime
select @duration='1900-01-01 00:53:00.000'
SELECT DATEDIFF(MI,0, @Duration)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2013-06-04 : 02:07:11
thanks
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-06-04 : 03:21:02
quote:
Originally posted by esthera

thanks


welcome
Which one you used?
As per Visakh's post, DATEDIFF(MI,0, @Duration) gives you the number of seconds from date 1900-01-01

Check the difference between two posts
declare @duration datetime
select @duration='2013-01-01 00:53:00.000'
SELECT DATEPART(MI, @Duration)
SELECT DATEDIFF(MI, 0, @Duration)



--
Chandu
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2013-06-04 : 03:48:23
thanks for pointing that out

I tried that different options and ended up using

declare @duration datetime
select @duration='1900-01-01 00:53:00.000'
SELECT DATEPART(MI, @Duration)

which seems to be what i want
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-06-04 : 03:52:56
quote:
Originally posted by esthera

thanks for pointing that out

I tried that different options and ended up using

declare @duration datetime
select @duration='1900-01-01 00:53:00.000'
SELECT DATEPART(MI, @Duration)

which seems to be what i want


OK...

--
Chandu
Go to Top of Page
   

- Advertisement -