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)
 Varchar to Number Conversion

Author  Topic 

dim
Yak Posting Veteran

57 Posts

Posted - 2010-07-20 : 10:51:34
Hi,

I have a column which is of type varchar and represents datetime information.
E.g. 2010-06-21 07:22:21

I have a requirement wherein I need to get only the minutes part out of the whole string like 07:22 should be 442 minutes as the output.

I need a suggestion about the way to achieve this task.

Thank You,


Dp

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2010-07-20 : 11:01:25
SELECT DATEDIFF(minute,DATEADD(dd,0,DATEDIFF(dd,0,'2010-06-21 07:22:21')),'2010-06-21 07:22:21')
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-20 : 11:06:46
declare @varchar_date varchar(20)
set @varchar_date ='2010-06-21 07:22:21'
select datediff(minute,0,right(@varchar_date ,8))

Also make sure to read this post
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/29/understanding-datetime-column-part-iv.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -