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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I calculate the last day of the current month?

Status
Not open for further replies.
Apr 3, 2002
25
FR
I need to return the date of the last day of the current month, in the correct format.

Help.
 

Try the following to get the last day of the month:

Number Var LastDay;
If month(CurrentDate) in [1,3,5,7,8,10,12] then LastDay:=31 else if Month(CurrentDate) in [4,6,9,11] then Lastday:=30 else if remainder(year(Currentdate)/4)=0 then LastDay:=29 else Lastday:=28;

Date(year(CurrentDate),Month(CurrentDate),LastDay)
Software Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
Dear GazzaMuffin:

This formula works for me:

//Crystal 8.0 Formula, Crystal Syntax
local datevar MD;
md := Date(Year(CurrentDate),Month(CurrentDate),1);
dateadd("M",1, md)-1
//formula end

Hope this is helpful,
ro Rosemary Lieberman
rosemary@microflo.com, Microflo provides expert consulting on MagicTSD and Crystal Reports.
 
Don's formula won't work for Feb 28, 1900 (not a leap year but is according to Don's formula)

Rosemary's will only work for Cr8.0 and Cr8.5 users.

My suggestion is...
numbervar m:=month(currentdate) + 1;
numbervar y:=year(currentdate);
if m>12 then (m:=m-12; y:=y+1);
Date(y,m,1) -1

Which will work for CR6 and CR7. Editor and Publisher of Crystal Clear
 
This formula works for me:

dateserial(year(currentdate), month(currentdate)+1, 1-1)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top