on 08-09-2011 8:40 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.