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
 diff between two dates

Author  Topic 

raky
Aged Yak Warrior

767 Posts

Posted - 2008-08-20 : 07:17:35
hi,

I want to find the difference between two columns whose datatype is datetime in terms of noofdaysandtime.

Please help me.

Thanks...

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-20 : 07:22:10

Read about datediff function in sql server help file

Madhivanan

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

raky
Aged Yak Warrior

767 Posts

Posted - 2008-08-20 : 07:25:29
quote:
Originally posted by madhivanan


Read about datediff function in sql server help file

Madhivanan

Failing to plan is Planning to fail



i know how to find interms of noofdays

for eg select datediff(day,fromdate,todate)

but i want accurated diff between two dates in terms of noofdays along with time..plz help
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-20 : 07:28:36
quote:
Originally posted by raky

quote:
Originally posted by madhivanan


Read about datediff function in sql server help file

Madhivanan

Failing to plan is Planning to fail



i know how to find interms of noofdays

for eg select datediff(day,fromdate,todate)

but i want accurated diff between two dates in terms of noofdays along with time..plz help


Can you post some sample and expected result?

Madhivanan

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

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-20 : 08:21:04
quote:
Originally posted by raky

quote:
Originally posted by madhivanan


Read about datediff function in sql server help file

Madhivanan

Failing to plan is Planning to fail



i know how to find interms of noofdays

for eg select datediff(day,fromdate,todate)

but i want accurated diff between two dates in terms of noofdays along with time..plz help



if you want the accuracy in terms of hour
then use dateadiff(hour, fromdate, todate)

or up to minute
dateadiff(minute, fromdate, todate)


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

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-20 : 09:23:40
[code]SELECT CAST(DATEDIFF(ss,StartDate,EndDate)/86400 AS varchar(10))+ ' Days'
+ CAST((DATEDIFF(ss,StartDate,EndDate)%86400)/3600 AS varchar(10)) + ' Hours'
+CAST(((DATEDIFF(ss,StartDate,EndDate)%86400)%3600)/60 AS varchar(10)) + ' Minutes'
+CAST((((DATEDIFF(ss,StartDate,EndDate)%86400)%3600)/60)%60 AS varchar(10)) +' Seconds'[/code]
Go to Top of Page
   

- Advertisement -