Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
hi there i have a date , it could be a random date, declare , @dateend datefor example set @dateend= '2012-02-28'how could i know if this date is the last day of the month???many thanks in advancedkind regards
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts
Posted - 2012-08-23 : 17:20:09
if month(@dateend) <> month(dateadd(Day, 1, @dateend)) print 'End of month!'=================================================We are far more concerned about the desecration of the flag than we are about the desecration of our land. -Wendell Berry
Lamprey
Master Smack Fu Yak Hacker
4614 Posts
Posted - 2012-08-23 : 17:37:03
Maybe this will help:
DECLARE @dateend DATETIME = '2012-02-28';SELECT CASE WHEN @dateend = DATEADD(DAY, - 1, DATEADD(MONTH, DATEDIFF(MONTH, 0, @dateend) + 1, 0)) THEN 'Month End' ELSE 'Not Month End' END
EDIT: Got distracted at work.. so a little late to teh party.. ;)
sebastian11c
Posting Yak Master
129 Posts
Posted - 2012-08-23 : 18:05:51
thanks both of you lamprey and bustaz koolnice coderegards