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,490 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: 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.

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…
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 …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

680 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