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,489 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

789 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