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 Chris Miller 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 Month 2

Status
Not open for further replies.

jason8643

MIS
May 28, 2003
7
US
I'm attempting to only pull back the last day of month in a recordset for each month for the entire year. Does anyone know if there is a simple formula to make Crystal retrieve this?


thanks!
 
The following will return the date of the last day of the month:


If month({DateField}) in [1,3,5,7,8,10,12] then date(year(DateField}), month({Datefield}),31) else

If month({DateField}) in [4,6,9,11] then date(year(DateField}), month({Datefield}),30) else

If remainder(year({DateField}),4)=0 then date(year(DateField}), month({Datefield}),29) else
//above handles leap years

date(year(DateField}), month({Datefield}),28) else

If this is not what you are looking for let me know.



Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
 
This will work for you as well:

DateAdd("d",-1,Date(Year(DateAdd("m", 1, {TABLE.DATE})),Month(DateAdd("m", 1, {TABLE.DATE})),1))

~Brian
 
Or there's always:

dateadd("M",1,cdate(year(currentdate),month(currentdate),1))-1

-k
 
Oooops, missed your requirement there about the recordset, replace currentdate with your field:

{table.date} = dateadd("M",1,cdate(year({table.date}),month({table.date}),1))-1

This won't be extremely efficient from within Crystal, so consider building out this formula in a SQL Expression, and then filtering where {table.date} = {%lastdateofmonth}

That way the database can filter it.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top