Home All Groups Group Topic Archive Search About

calculating a date difference...

Author
25 Aug 2005 7:35 PM
certolnut
Hi all...

Is there a function to calculate the number of months between 2 different
dates??

Example: @varNumberOfMonths = DATEDIFF(month,'08/01/05','07/01,05' )

Thanks in advance for any help...

Author
25 Aug 2005 7:48 PM
JT
You have a misplaced comma. Try this:
DATEDIFF(month,'08/01/05','07/01/05' )

Show quote
"certolnut" <whitney_n***@hotmail.com> wrote in message
news:e6CKawaqFHA.528@TK2MSFTNGP09.phx.gbl...
> Hi all...
>
> Is there a function to calculate the number of months between 2 different
> dates??
>
> Example: @varNumberOfMonths = DATEDIFF(month,'08/01/05','07/01,05' )
>
> Thanks in advance for any help...
>
Author
25 Aug 2005 7:52 PM
Aaron Bertrand [SQL Server MVP]
Did you try it?


DECLARE @NumberOfMonths SMALLINT
-- we know it's a VAR because @, no var prefix necessary

SET @NumberOfMonths = DATEDIFF(MONTH, '20050701', '20050801')
-- do not use mm/dd/yy format

PRINT @NumberOfMonths



Show quote
"certolnut" <whitney_n***@hotmail.com> wrote in message
news:e6CKawaqFHA.528@TK2MSFTNGP09.phx.gbl...
> Hi all...
>
> Is there a function to calculate the number of months between 2 different
> dates??
>
> Example: @varNumberOfMonths = DATEDIFF(month,'08/01/05','07/01,05' )
>
> Thanks in advance for any help...
>
Author
25 Aug 2005 8:02 PM
certolnut
Thats got it, actually I had no idea that I was that close....lucky guess
(but not lucky enough)

Thanks so much for your help!!
Show quote
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message
news:Oggdd5aqFHA.3352@TK2MSFTNGP14.phx.gbl...
> Did you try it?
>
>
> DECLARE @NumberOfMonths SMALLINT
> -- we know it's a VAR because @, no var prefix necessary
>
> SET @NumberOfMonths = DATEDIFF(MONTH, '20050701', '20050801')
> -- do not use mm/dd/yy format
>
> PRINT @NumberOfMonths
>
>
>
> "certolnut" <whitney_n***@hotmail.com> wrote in message
> news:e6CKawaqFHA.528@TK2MSFTNGP09.phx.gbl...
>> Hi all...
>>
>> Is there a function to calculate the number of months between 2 different
>> dates??
>>
>> Example: @varNumberOfMonths = DATEDIFF(month,'08/01/05','07/01,05' )
>>
>> Thanks in advance for any help...
>>
>
>
Author
25 Aug 2005 8:08 PM
Aaron Bertrand [SQL Server MVP]
> Thats got it, actually I had no idea that I was that close....lucky guess
> (but not lucky enough)

Hmmm, have you considered downloading the documentation?  Guessing kind of
slows development down.

http://www.aspfaq.com/2229
Author
25 Aug 2005 8:52 PM
certolnut
No offense meant, and I appreciate the help, but I defy anyone to get
anything other than the most rudimentary of help from that documentation...


Show quote
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message
news:uFK0iCbqFHA.2072@TK2MSFTNGP14.phx.gbl...
>> Thats got it, actually I had no idea that I was that close....lucky guess
>> (but not lucky enough)
>
> Hmmm, have you considered downloading the documentation?  Guessing kind of
> slows development down.
>
> http://www.aspfaq.com/2229
>
Author
25 Aug 2005 8:57 PM
Aaron Bertrand [SQL Server MVP]
> No offense meant, and I appreciate the help, but I defy anyone to get
> anything other than the most rudimentary of help from that
> documentation...

I disagree completely; this is the place to get help for SQL Server.  Are
you trying to tell me that the following article would not have helped you
in any way?

http://msdn.microsoft.com/library/en-us/tsqlref/ts_da-db_5vxi.asp
Author
25 Aug 2005 9:37 PM
certolnut
Certainly it does, no question, your right. But this documentation has
failed me in the past, so I felt the need to turn to other resources instead
of wasting time. I'm sorry if you felt this was a waste of yours....
Show quote
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message
news:umFnHebqFHA.2596@TK2MSFTNGP09.phx.gbl...
>> No offense meant, and I appreciate the help, but I defy anyone to get
>> anything other than the most rudimentary of help from that
>> documentation...
>
> I disagree completely; this is the place to get help for SQL Server.  Are
> you trying to tell me that the following article would not have helped you
> in any way?
>
> http://msdn.microsoft.com/library/en-us/tsqlref/ts_da-db_5vxi.asp
>

AddThis Social Bookmark Button