Solved

IsDate not working in Crystal Reports XI

Posted on 2014-11-04
4
628 Views
Last Modified: 2014-11-04
I have a varchar field and the value in it is 20140305, which is a valid date. I wrote the following so that I could display it as a date and it is not working. I would really appreciate the help.

if IsDate({MyTable.MyDateField} then
     ToText(CDate({MyTable.MyDateField}),"yyyymmdd")

I have tried other variations but one thing I did do was I wanted to see if my IsDate was returning as true so I coded it like this and got the text after the else:

if IsDate({MyTable.MyDateField} then
     ToText(CDate({MyTable.MyDateField}),"yyyymmdd")
else "Not Working"

I know that the value in my field is correct - pretty stumped.

Thanks for any help.
0
Comment
Question by:Peggy Bakos
  • 2
4 Comments
 
LVL 18

Expert Comment

by:vasto
ID: 40422691
My guess is that IsDate expects something that really looks like date and can be parsed for example : 1/1/2014, Jan 1, 2014, 1-1-2014 etc. I am not sure that a numeric string could be considered as a date except if it is converted to a number . However if you pass a number the date will be calculated as a number of days since 1/1/1900 ( or (12/31/1899)
The problem with your string is that if the format allows single month and day  2014121 could be Jan 21 2014 or Dec 1 2014 so I guess you need to add some kind of delimiter
0
 
LVL 34

Accepted Solution

by:
James0628 earned 500 total points
ID: 40422713
"20140305" is not a valid date, as far as IsDate is concerned.  If you try just IsDate ("20140305"), it will return False.

 If the string is always in that "yyyymmdd" form, you can use the Picture function to add "/"s, to make it a valid date for IsDate.

if IsDate(Picture ({MyTable.MyDateField}, "xxxx/xx/xx")) then
     ToText(CDate(Picture ({MyTable.MyDateField}, "xxxx/xx/xx")),"yyyyMMdd")

 However, if the string could be something else, you may need some additional tests.  And if the field could be null, you'd need to test for that first.

 Also, you say that the field is a string in the "yyyymmdd" form, but then you try to convert it to a date, and then back to a string in the same form, which seems kind of pointless (since it was in that form to start with).

 And, if you don't know, the format in your ToText function is wrong.  "mm" is for minutes.  "MM" is for months.

 James
0
 

Author Closing Comment

by:Peggy Bakos
ID: 40422791
Thank you for the quick reply and the answer to my question. I did not know that the mm was for minutes, thank you for that as well. I had never seen the Picture function before, something new everyday. I was able to also get the value that was in yyyymmdd format into MM/dd/yyyy format. It look as I expect it to.
0
 
LVL 34

Expert Comment

by:James0628
ID: 40422888
You're welcome.  Glad I could help.

 James
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

20 Experts available now in Live!

Get 1:1 Help Now