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 2000 Forums
 SQL Server Development (2000)
 calculate month

Author  Topic 

wided
Posting Yak Master

218 Posts

Posted - 2010-10-04 : 05:18:46
How to calculate the number of month
when i have 2 date

(By using the functions date or others functions)

example

Date1 = '20100401' or other date

given date ='20100630'

if i use datediff , i have 2 months as a result, so i want to have 3
thanks

PS: sql2000 or sql2005

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-04 : 05:27:52
In your example the result of 2 is correct because june isn't finished.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

wided
Posting Yak Master

218 Posts

Posted - 2010-10-04 : 05:36:18
no webfred

the result may be 3

month4, month5 and month6
thanks
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-04 : 06:09:14
What I meaned was if you take 20100701 instead of 20100630 then the result will be 3 because then the june is finished.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

wided
Posting Yak Master

218 Posts

Posted - 2010-10-04 : 06:16:50
The result between '20100701' and '20100630'
must be zero

I want to calculate the interval of interruption in months between 2 dates
this is my program
Go to Top of Page

wided
Posting Yak Master

218 Posts

Posted - 2010-10-04 : 06:44:48

please
I await your reply
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-04 : 07:16:49
So let's say for the first date you are always giving the first day of the month i.e. 20100401 and for the second day you are always giving the last day of the month i.e 20100630 or for example 20100831.
In this case you can add one day to the second date.

select datediff(month,'20100401',dateadd(dd,1,'20100630'))

Is that what you want?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-04 : 07:19:42
And also take the time to read this:
http://www.sqlteam.com/article/datediff-function-demystified


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

wided
Posting Yak Master

218 Posts

Posted - 2010-10-04 : 07:30:55

i hope so

i think that is the unique solution


thanks
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-04 : 07:32:01
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -