cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal reports - - Bad Date format

Former Member
0 Kudos

Dear Experts,

I am using crystal developer 11. I am working with a 24 char strng that has a date (as a string) in the middle of it. I am using the mid function to extract the date two chars at a time because it includes the "/" char between each date part. I am then using Cdate to convert the resulting string to a date. I receive no errors when I check for errors, however, when I return to the main design and try to use this newly created date field against another actual date, I recieve an error "Bad Date format" back on the Cdate conversion in the formula. Is there a way to format this Cdate to avoid this error or possibly extract the date from the string and convert it to a date in a better way. Any help would be appreciated

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thank You,

below is the formula:

dim eve_date as string

dim eve_date1 as string

dim eve_date2 as string

dim eve_date3 as string

dim result as date

eve_date = mid({CMTRNEVE.POSTED}, 12, 02)

eve_date1 = mid({CMTRNEVE.POSTED}, 15, 02)

eve_date2 = "2011"&eve_date&eve_date1

result = cdate(eve_date2)

formula = Result

Next is the code that creates the error

Placing the formula on the report:

@GetDate

please note that when checking the formula no errors - when running the report - "Bad Date format" on the result = cdate(eve_date2) line - thx agaiin

former_member292966
Active Contributor
0 Kudos

Hi,

Before you use CDate, check to make sure your string is a valid date with the IsDate function like:

dim eve_date as string
dim eve_date1 as string
dim eve_date2 as string
dim eve_date3 as string
dim result as date

eve_date = mid({CMTRNEVE.POSTED}, 12, 02)
eve_date1 = mid({CMTRNEVE.POSTED}, 15, 02)

eve_date2 = "2011"&eve_date&eve_date1

If IsDate (eve_date2) Then 
    result = cdate(eve_date2) 
Else result = Date (0, 0, 0)

formula = Result

I have the formula returning a NULL date if it IsDate fails. It may be better to display the string instead of a NULL date so you can see what is being passed.

Hope this helps,

Brian

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

     I am getting bad date format string while converting  string to date like the below code.

     if totext(Cdate({WipAllocationInfo.InWiseDate}),"MMddyyyy")<>"12301899" then

     formula=totext(Cdate({WipAllocationInfo.InWiseDate}),"MM/dd/yyyy")

    else

    formula="/ /"

    end if

     Above is the basic syntax..

Thanks,

Chakradhar.

abhilash_kumar
Active Contributor
0 Kudos

Please post this as a new Discussion and we'll be happy to help you.

-Abhilash

Former Member
0 Kudos

Will you please help me to start a new discussion hence i am new to this. Where is the option to start new discussion .

Thanks

Chakradhar.

abhilash_kumar
Active Contributor
0 Kudos

On the top right, look for the Create option and select Discussion from the drop-down.

-Abhilash

Former Member
0 Kudos

Hi Kevin,

Try to update the post with your formula and the datestring which you are trying to extract. This will help anyone to understand better and reply.

Thanks,

Sastry