IsDate not working in Crystal Reports XI

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.
Peggy BakosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vastoCommented:
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
James0628Commented:
"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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Peggy BakosAuthor Commented:
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
James0628Commented:
You're welcome.  Glad I could help.

 James
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.