Solved

# Crystal Reports  Current Date

Posted on 2012-09-18
632 Views
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?
0
Question by:garyjgs

LVL 12

Expert Comment

try Year(CurrentDate)
0

LVL 100

Expert Comment

Looks good

mlmcc
0

LVL 19

Expert Comment

In full that would be

Date(Year(CurrentDate), 1, 1)
0

Author Comment

I have attached a screen print of what I am trying to accomplish with current year
formula-screen-print.docx
0

LVL 12

Accepted Solution

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....
``````
0

LVL 19

Expert Comment

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
``````
0

Author Closing Comment

This worked best for the scenario in the report.  Thank you.
0

LVL 19

Expert Comment

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
0

## Featured Post

### Suggested Solutions

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.