LAST DAY OF THE MONTH

LAST DAY OF THE MONTH

Post by Noorali Issan » Fri, 12 Jul 2002 15:41:08



DEAR ALL

I am wanna know about last day of the month, let's assume I will give input
like

select last_day(2002-01-04)

It will return me 31, the last day of the month

Is there any function available in sql server ?

regards
Noor
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Noorali Issani
Database Developer Tel(Off):+92(021)-452-8801(EXT 208)
Tel(Res):+92(021)633-1912

------------------- Visit: My
Resume --------------------------------------------------------------------
Just Believe In YourSelf...every thing will fall in order But dont forget to
pray...Pray as if every thing depends on Allah, and work as if every thing
depends on
you. --------------------------------------------------------------------

 
 
 

LAST DAY OF THE MONTH

Post by Marc Scheune » Fri, 12 Jul 2002 21:44:14


Quote:>I am wanna know about last day of the month, let's assume I will give input
>like
>select last_day(2002-01-04)

>It will return me 31, the last day of the month
>Is there any function available in sql server ?

No, but it's pretty easy to write one yourself - have a look:


returns int
as
begin




  -- check for leap year

  begin


    begin



    end
  end


    case












      else -1
    end


end

Marc

 
 
 

LAST DAY OF THE MONTH

Post by lindawi » Fri, 12 Jul 2002 23:06:52


Noor,

Quote:> I am wanna know about last day of the month, let's assume I will give
> input like

> select last_day(2002-01-04)

> It will return me 31, the last day of the month

> Is there any function available in sql server ?

You can use an expression:

This just removes that day, concatenates '01' to reset to the
beginning of the month, adds one month, and subtracts one day.



select dateadd(dd, -1, dateadd(mm, 1,

Linda