Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

IsDate not working in Crystal Reports XI

Posted on 2014-11-04
4
Medium Priority
?
891 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
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 …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 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