-4

Trying to see if today is the end of the month and if it is run the code, I am thinking to use EOMONTH and getdate but I'm not sure how.

Bill Roberts
  • 81
  • 2
  • 8

2 Answers2

1
IF(GETDATE() = EOMONTH(GETDATE()))
BEGIN
    PRINT 'TODAY IS THE END OF MONTH' 
END
ELSE 
BEGIN
    PRINT 'TODAY IS NOT THE END OF MONTH'
END

http://rextester.com/NAH54861

Ian-Fogelman
  • 1,595
  • 1
  • 9
  • 15
1

In MS SQL Sever GETDATE() returns the current date and time, and CAST(GETDATE() AS DATE) returns today's date in yyyy-mm-dd format without including the time. EOMONTH() returns type date so EOMONTH(GETDATE()) returns the last day of the current month in yyyy-mm-dd format. Therefore if you're using a statement block:

IF CAST(GETDATE() AS DATE) = EOMONTH(GETDATE())
BEGIN
    PRINT 'Today is the end of the month'
END
ELSE
BEGIN
    PRINT 'Today is not the end of the month'
END

And if you're just looking for a basic IF..ELSE without the statement block:

IF CAST(GETDATE() AS DATE) = EOMONTH(GETDATE())
    PRINT 'Today is the end of the month'
ELSE
    PRINT 'Today is not the end of the month'
sripley
  • 125
  • 5