# 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?
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
try Year(CurrentDate)
Commented:
Looks good

mlmcc
Commented:
In full that would be

Date(Year(CurrentDate), 1, 1)
Author Commented:
I have attached a screen print of what I am trying to accomplish with current year
formula-screen-print.docx
Commented:
This will be the syntax for your if statement:

``````IF (Command.PR Period End Date) >= date(year(currentDate), 01, 01) and (Command.PR Period End Date) <= date(year(currentDate), 01, 15) then 1 else....
``````

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
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
``````

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
``````
Author Commented:
This worked best for the scenario in the report.  Thank you.
Commented:
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
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.