?
Solved

Crystal Reports  Current Date

Posted on 2012-09-18
8
Medium Priority
?
639 Views
Last Modified: 2012-09-19
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
Comment
Question by:garyjgs
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 12

Expert Comment

by:Jared_S
ID: 38412278
try Year(CurrentDate)
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 38412287
Looks good

mlmcc
0
 
LVL 19

Expert Comment

by:GJParker
ID: 38412971
In full that would be

Date(Year(CurrentDate), 1, 1)
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:garyjgs
ID: 38413274
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

by:
Jared_S earned 2000 total points
ID: 38413476
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....

Open in new window

0
 
LVL 19

Expert Comment

by:GJParker
ID: 38413493
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

0
 

Author Closing Comment

by:garyjgs
ID: 38414312
This worked best for the scenario in the report.  Thank you.
0
 
LVL 19

Expert Comment

by:GJParker
ID: 38414359
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question