Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

IsDate not working in Crystal Reports XI

Posted on 2014-11-04
4
Medium Priority
?
941 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 35

Accepted Solution

by:
James0628 earned 2000 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 35

Expert Comment

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

 James
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

926 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