• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1013
  • Last Modified:

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.
0
Peggy Bakos
Asked:
Peggy Bakos
  • 2
1 Solution
 
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
 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now