December 20, 2006 at 10:22 am
Does anyone no a way that I could code a query that would always give the last day of the crrrent month. Where it had 30 or 31 days.
December 20, 2006 at 11:05 am
Sure:
DECLARE @d DATETIME
SET @d = '2006-10-24'
SELECT DAY(DATEADD(d, -DAY(DATEADD(m,1,@d)),DATEADD(m,1,@d))) AS 'Last day of the month'
******************
Dinakar Nethi
Life is short. Enjoy it.
******************
December 20, 2006 at 11:24 am
Thanks!
Merry Christmas!
December 21, 2006 at 7:08 am
This works to give you the last day of the previous month, in case you wanted that:
select getdate()-datepart(day,getdate())
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply