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)
 Simplest way to Calclulate LAST day of month

Author  Topic 

abarsami
Yak Posting Veteran

68 Posts

Posted - 2002-04-18 : 19:07:21
I would like to supply the month and year ... and have it tell me the last day of that month and year.

So if I say 04, 2002 ... I want to get back 30

Anyone know an easy way to do this.

Thanks



robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-04-18 : 19:36:58
CREATE PROCEDURE GetLastDay @month int, @year int AS
SELECT CASE
WHEN @month IN (1,3,5,7,8,10,12) THEN 31
WHEN @month=2 THEN CASE WHEN (@year%400<>0 AND @year%100=0 OR @year%4=0) THEN 28 ELSE 29 END
ELSE 30 END AS LastDay


Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2002-04-18 : 20:09:29
Try this out....


declare @tDate datetime
set @tDate = '20011224'
Select dateadd(d,-(day(dateadd(m,1,@tDate))),dateadd(m,1,@tDate))


HTH

DavidM

Tomorrow is the same day as Today was the day before.
Go to Top of Page
   

- Advertisement -