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 2008 Forums
 Transact-SQL (2008)
 hi could i know if a date is the last day of the m

Author  Topic 

sebastian11c
Posting Yak Master

129 Posts

Posted - 2012-08-23 : 17:11:34
hi there


i have a date , it could be a random date,
declare , @dateend date

for example
set @dateend= '2012-02-28'

how could i know if this date is the last day of the month???


many thanks in advanced

kind 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
Go to Top of Page

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.. ;)
Go to Top of Page

sebastian11c
Posting Yak Master

129 Posts

Posted - 2012-08-23 : 18:05:51
thanks both of you lamprey and bustaz kool

nice code

regards
Go to Top of Page
   

- Advertisement -