Hello:
If I have middle month date ,
for example '2005-04-22',
how can I get end month date, in this case
'2005-04-30'?
I need a solution for any date.
Thanks,
GBTry:
dateadd(d, -(day(@.dt)),@.dt)
"GB" <v7v1k3@.hotmail.com> wrote in message
news:ro2Pf.22370$Ui.5143@.edtnps84...
> Hello:
> If I have middle month date ,
> for example '2005-04-22',
> how can I get end month date, in this case
> '2005-04-30'?
> I need a solution for any date.
> Thanks,
> GB|||DECLARE @.date SMALLDATETIME;
SET @.date = '20050422';
DECLARE @.start SMALLDATETIME, @.endDay SMALLDATETIME;
SET @.start = DATEDIFF(DAY,0,@.date);
SET @.endDay = DATEADD(MONTH,1,@.date)-DAY(@.start);
SELECT @.endDay;
"GB" <v7v1k3@.hotmail.com> wrote in message
news:ro2Pf.22370$Ui.5143@.edtnps84...
> Hello:
> If I have middle month date ,
> for example '2005-04-22',
> how can I get end month date, in this case
> '2005-04-30'?
> I need a solution for any date.
> Thanks,
> GB
>|||mason, that gives the last day of the *previous* month...
"mason" <masonliu@.msn.com> wrote in message
news:%23EIDutWQGHA.1676@.TK2MSFTNGP14.phx.gbl...
> Try:
> dateadd(d, -(day(@.dt)),@.dt)
>
> "GB" <v7v1k3@.hotmail.com> wrote in message
> news:ro2Pf.22370$Ui.5143@.edtnps84...
>|||This solution gives PREVIOUS month date,
for '2005-04-22' it gives '2005-03-31'
I need current month end date, in this case '2005-04-30'.
Thanks,
GB
"mason" <masonliu@.msn.com> wrote in message
news:%23EIDutWQGHA.1676@.TK2MSFTNGP14.phx.gbl...
> Try:
> dateadd(d, -(day(@.dt)),@.dt)
>
> "GB" <v7v1k3@.hotmail.com> wrote in message
> news:ro2Pf.22370$Ui.5143@.edtnps84...
>|||Misfire. :p
dateadd(d, - (day(dateadd(m,1,@.dt))),dateadd(m,1,@.dt)
)
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:eEPYvyWQGHA.5092@.TK2MSFTNGP11.phx.gbl...
> mason, that gives the last day of the *previous* month...
>
> "mason" <masonliu@.msn.com> wrote in message
> news:%23EIDutWQGHA.1676@.TK2MSFTNGP14.phx.gbl...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment