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
 date difference

Author  Topic 

jogin malathi
Posting Yak Master

117 Posts

Posted - 2007-07-30 : 05:30:58
select datediff(ss,In_time,Out_time)
select datediff(ss,'23:22:11','00:40:50')

But out time is as 12/6/2007 00:40:50
and in time is as 11/6/2007 23:22:11

when iam trying to get the date diff it gives the negitive value as
Column
------------
-81681

how can i get the actual difference




Malathi Rao

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-30 : 05:37:32
That is the actual difference in SECONDS because you have set the DATADIFF to calculate seconds.
And when you do not provide the DATE part, SQL Server assumes the date of January 1, 1900.

Try to add the date part too...

set dateformat dmy
select datediff(ss,'11/6/2007 23:22:11', '12/6/2007 00:40:50')


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -