Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Last Day of a month query

  • Thread starter Thread starter eo
  • Start date Start date
Status
Not open for further replies.

eo

MIS
Joined
Apr 3, 2003
Messages
809
Hi,

I am trying to create an insert statement to populate the date dimension. One of the columns relates to whether the date falls on a calendar month end (another on a quarter end, and another on a year end). I have tried all sorts of statements to try and work out if a date falls on a calendar month, quarter and year end, but no luck so far.

Does anyone have any ideas?

EO
Hertfordshire, England
 
Answewred my own question, and in case anyone else wondered:

Code:
case when MONTH (DATEADD(d, 1, [Date])) > MONTH([Date]) then 'Y' else 'N' end

EO
Hertfordshire, England
 
Last day of month:
Code:
SELECT DATEADD(month,DATEDIFF(month, 0,GETDATE())+1,0) -1

Last day of year:
(This is overkill since the last day of any year is 12/31)
Code:
SELECT DATEADD(year,Datediff(year ,0,getdate())+1,0)-1

Not sure how to do quater end since that can vary on what a quarter is to your business. Some business use a fiscal quarter not a calendar quarter.
 
Try this.

IF YEAR(CURRENT_TIMESTAMP) <> YEAR(DATEADD(day, 1, CURRENT_TIMESTAMP))
PRINT 'Today is the last day of the year.'
ELSE
IF MONTH(CURRENT_TIMESTAMP) <> MONTH(DATEADD(day, 1, CURRENT_TIMESTAMP))
PRINT 'Today is the last day of the month but not the last day of the year.'
ELSE
PRINT 'Today is not the last day of the month.';
GO

Ordinary Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top