Link to home
Start Free TrialLog in
Avatar of garyjgs
garyjgsFlag for United States of America

asked on

Crystal Reports Current Date

There are a series of dates in a formula for a Crystal Report.  The date is expressed in the formula as: date(2012,01,01).  How can the year 2012 be changed to identify "current year" as not have to change the formula every year?
Avatar of Jared_S
Jared_S

try Year(CurrentDate)
Avatar of Mike McCracken
Looks good

mlmcc
In full that would be

Date(Year(CurrentDate), 1, 1)
Avatar of garyjgs

ASKER

I have attached a screen print of what I am trying to accomplish with current year
formula-screen-print.docx
ASKER CERTIFIED SOLUTION
Avatar of Jared_S
Jared_S

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You'll beed to amend your formula to something like

Local NumberVar CYear := Year(CurrentDate);

If {command.PR Period End Date} >= Date(CYear,01,01) and {command.PR Period End Date} <= Date(CYear,01,15) then 1 else
If {command.PR Period End Date} >= Date(CYear,01,16) and {command.PR Period End Date} <= Date(CYear,01,31) then 2 else
.
.
and so on for each line

Open in new window



you will also need to change the line for teh February end date to handle leap years correctly i.e.

If {command.PR Period End Date} >= Date(CYear,02,16) and {command.PR Period End Date} < Date(CYear,03,01) then 4 else

Open in new window

Avatar of garyjgs

ASKER

This worked best for the scenario in the report.  Thank you.
Isn't that the same as I posted in my earlier post ?

don't forget if you dont change the line that tests for end of feb the formula will fail for non leap years as ther isn't a 29th