Solved

Formula to format date string field in "DD/MM/YYY" to match date range parameter in Crystal Reports

Posted on 2006-06-21
5
1,481 Views
Last Modified: 2008-02-01
I have a date field held in a string in "DD/MM/YYY"  format and want to use it in record selection criteria to match a date range parameter. I've tried converting it to a formula using:

Right ({Transit Analysis PO Details.CompletedDate},4 ) + '/' + Left(Right ({Transit Analysis PO Details.CompletedDate},4),2) + '/' + Left ({Transit Analysis PO Details.CompletedDate},2 )

but this does not work. Hoshould I change the formula to get it to work or do I need to take a different approach?
0
Comment
Question by:JamesJMcDonnell
  • 3
  • 2
5 Comments
 
LVL 28

Accepted Solution

by:
bdreed35 earned 500 total points
ID: 16955672
Is it DD/MM/YYY with a three digit year or DD/MM/YYYY with a 4 digit year?

Your logic should be like this:

date(val(Right ({Transit Analysis PO Details.CompletedDate},4)), val(mid({Transit Analysis PO Details.CompletedDate},4,2)), val(left({Transit Analysis PO Details.CompletedDate},2)))

Keep in mind that this will not pass to the database in SQL and will only be performed on the client side, thus being less efficient.
You can also create a SQL Expression convert the field to a date and then your record selection would look like this:

{%SQL Exp Name} in {?Date Range}
0
 

Author Comment

by:JamesJMcDonnell
ID: 16956051
It's DD/MM/YYYY. I'm only using it in Crystal having formatted it from a SQL Server database datefield in a DateView. I had tried mid earlier and when it didn't work found the Left(Right use in an answer on this site. Was wondering if there might be a problem with leading zeroes being dropped for dates like 01/06/2006 and that someone might  have formula making use of Ltrim etc. Thanks, bdreed95, I will try your version using Date and Val when I get back to my work PC to-morrow morning.
0
 

Author Comment

by:JamesJMcDonnell
ID: 16958230
Thanks BDreed35 your code works. I have  a connected problem now. I want to display the date range on the report and using a normal formula for this,
e.g. minimum({?DateRange}) & " to " & maximum({?DateRange}) the date comes out in MM/DD/YYYY format. This is not so easy to reaarange as leading zeroes are dropped as in e.g. 6/1/2006 to 6/30/2006. How might this conversion be done?
0
 
LVL 28

Expert Comment

by:bdreed35
ID: 16959006
Write it this way:

totext(minimum({?DateRange}),"MM/DD/YYYY") & " to " & totext(maximum({?DateRange}),"MM/DD/YYYY")
0
 

Author Comment

by:JamesJMcDonnell
ID: 16960398
It turned out that the format of the date range was affected by settings on the server I was running the report on. Applying your formula instead of the standard one then caused it to come out as 06/DD/YYYY to 06/DD/YYYY !?
Thanks for your help
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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. …
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now