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 

DHL
Starting Member

16 Posts

Posted - 2007-10-01 : 10:38:24
Hi,

I have a problem with the following:

I have 2 dates in the following format mm/dd/yyyy hh:mm:ss AM.

I would like to measure the difference between 2 dates (Date1 and Date2).
When I use the following expression "DATEDIFF(d, Date1, Date2)" I get a value
without decimals. How can I have a value in days with decimals like e.g. 5.38? If you calculate this using Excel you get decimals behind the comma.

Please help!!!

Thanks!

DHL

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-10-01 : 10:40:01
calculate the date diff in hours and then divide by 24.
or calc the diff in minutes and divide by 60*24 = 1440

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-01 : 10:53:34
http://www.sqlteam.com/article/datediff-function-demystified



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

DHL
Starting Member

16 Posts

Posted - 2007-10-01 : 11:01:03
This is not really working as this field is now not recognized as a value. Please help, I need to have values in place...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-10-01 : 11:05:05
quote:
Originally posted by DHL

This is not really working as this field is now not recognized as a value. Please help, I need to have values in place...


What do you mean by this ?


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

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-02 : 01:57:51
It means do didn't like the article and will not bother to write code for himself to solve his issue.
It means he wants us to ignore Spirit1's suggestion and keep posting other solutions which OP can try without modifications.



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

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-10-02 : 07:36:31
OK. I will do just that. Ignore (all).


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

Go to Top of Page
   

- Advertisement -