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 TouchToneTommy 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

Status
Not open for further replies.

PT5SS

Programmer
Oct 6, 2000
5
US
I used to use a function called LAST_DAY in PL/SQL.

The function would return the last day of a month based on a given year.

Is there a similar function available in SQL 7.0
 
No, but you may use following:
dateadd(dd,-1,dateadd(mm,1,'10/01/2000'))
returns 2000-10-31 - last day of the 10-th month.

Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Hi,

Um... that code would return the last day of the 9th month, not the 10th month.

I would do this:

DECLARE @mydate datetime
SET @mydate = '11/01/2000'
SELECT DAY(dateadd(dd,-1, @mydate))

to get the last day of a month (of October in this case). Note the lack of the second dateadd call.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top