Tuesday, March 27, 2012

About "MONTH" datediff

Hi,
I'm trying to make a "MONTH" DATEDIFF result.
If the month of GETDATE() is January then I want the result is the December
of last year.
Like GETDATE() = 200601 THEN GETDATE()-1(Month) = 200512
How can I do this?
Thanks for any advice!
Angi
declare @.dt datetime
set @.dt = getdate()
SELECT DATEADD(month, -1, @.dt)
William Stacey [MVP]
"Angi" <enchiw@.msn.com> wrote in message
news:e6ueCBgBGHA.736@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I'm trying to make a "MONTH" DATEDIFF result.
> If the month of GETDATE() is January then I want the result is the
> December of last year.
> Like GETDATE() = 200601 THEN GETDATE()-1(Month) = 200512
> How can I do this?
> Thanks for any advice!
> Angi
>
|||Wow, Thanks!
Angi
"William Stacey [MVP]" <william.stacey@.gmail.com> glsD:eLgUTGgBGHA.4032@.TK2MSFTNGP10.phx.g bl...
> declare @.dt datetime
> set @.dt = getdate()
> SELECT DATEADD(month, -1, @.dt)
>
> --
> William Stacey [MVP]
> "Angi" <enchiw@.msn.com> wrote in message
> news:e6ueCBgBGHA.736@.TK2MSFTNGP10.phx.gbl...
>

No comments:

Post a Comment