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)
 Datetime

Author  Topic 

ilimax
Posting Yak Master

164 Posts

Posted - 2011-02-15 : 00:11:43
201102141934 YYYYMMDDHHSS

This function give me excellent result from my string... 19 hours

DateDiff(Hour, convert(datetime, substring(timein,1,8)), GetDate())

I have problem to get difference between Getdate() and this time string.

If I change 8 into 12 in substring paramater, I got error ...

I want to get result 4 if I run this at 23:34.

Anybody have idea ...???

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-02-15 : 01:03:18
Is "201102141934" a string or an integer?



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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-02-15 : 01:04:48
SELECT DATEDIFF(MINUTE, STUFF(STUFF(STUFF(TimeIn, 11, 0, ':'), 9, 0, ' '), GETDATE())



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

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-02-15 : 03:06:57
quote:
Originally posted by Peso

SELECT DATEDIFF(MINUTE, STUFF(STUFF(STUFF(TimeIn, 11, 0, ':'), 9, 0, ' '), GETDATE())



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





Perhaps one stuff is extra ?


SELECT DATEDIFF(MINUTE, STUFF(STUFF(timein, 11, 0, ':'), 9, 0, ' '), GETDATE())

Cheers
MIK
Go to Top of Page

ilimax
Posting Yak Master

164 Posts

Posted - 2011-02-15 : 08:42:37
quote:
Originally posted by Peso

Is "201102141934" a string or an integer?



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




String
Go to Top of Page

ilimax
Posting Yak Master

164 Posts

Posted - 2011-02-15 : 08:43:15
quote:
Originally posted by MIK_2008

quote:
Originally posted by Peso

SELECT DATEDIFF(MINUTE, STUFF(STUFF(STUFF(TimeIn, 11, 0, ':'), 9, 0, ' '), GETDATE())



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





Perhaps one stuff is extra ?


SELECT DATEDIFF(MINUTE, STUFF(STUFF(timein, 11, 0, ':'), 9, 0, ' '), GETDATE())

Cheers
MIK



Thanks .. Let me try ..Will let you know soon
Go to Top of Page

ilimax
Posting Yak Master

164 Posts

Posted - 2011-02-15 : 12:57:02
Works .. Great .. Tahnks Peso and MIK
Go to Top of Page
   

- Advertisement -