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)
 DateDiff for Month in decimal

Author  Topic 

chotup
Starting Member

3 Posts

Posted - 2008-12-19 : 23:06:32
hi All,
I am trying to use datediff fuunction. But problem is that it return interger for the month. Can someone suggest with me some code or function that returns date differnce for months in decimal?
Will really appreciate any help on this

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2008-12-19 : 23:08:03
wt is ur requirement
can u post some o/p
Go to Top of Page

chotup
Starting Member

3 Posts

Posted - 2008-12-19 : 23:13:55
well like i m using datediff(mm,'10/15/2008', '11/19/2008')

it gives me 1, but i need 1.1 here for 4 more days
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-12-19 : 23:47:31
Can you please explain why 4 more days would equal .1 of a month?

CODO ERGO SUM
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2008-12-19 : 23:55:07
Try This

SELECT CASE WHEN DATEDIFF(d,fromdate,enddate)>30 THEN DATEDIFF(d,fromdate,enddate)/30.0 ELSE 0 END AS 'MonthDifference'


Jai Krishna
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-20 : 04:47:37
SELECT DATEDIFF(DAY, FromDate, EndDate) / 30.436875E



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

- Advertisement -