Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Number to Date Post Reply Post New Topic
Author Message
Crysjen
Newbie
Newbie


Joined: 31 Mar 2010
Online Status: Offline
Posts: 4
Quote Crysjen Replybullet Topic: Number to Date
     Posted: 19 Apr 2010 at 3:11am
Hi,
 
Our current system reports date is the format CYYMMDD and crystal pull sthis through as a number. We initiaaly used this formula
 
date ((if left (totext({file.date}),1) = "1" then "20" else if left (totext({file.date}),1) = "0" then "19") &
(mid (totext ({file.date}),3,2)) & "," &
(mid (totext ({file.date}),5,1)) &
 (mid (totext ({file.date}),7,1)) & "," &
(mid (totext ({file.date}),8,2)))
 
and then our database was updated (No Idea how as iseries databases do not update anything). This caused is to get the 'Bad Date Format String' error. So then we started using the following
 
if len(totext({file.date})) > 10 then date ((if left (totext({file.date}),1) = "1" then "20" else if left (totext({file.date}),1) = "0" then "19") &
(mid (totext ({file.date}),3,2)) & "," &
(mid (totext ({file.date}),5,1)) &
 (mid (totext ({file.date}),7,1)) & "," &
(mid (totext ({file.date}),8,2)))
 
Now our database has updated again and this comes up blank. Does anyone know how to correct this as we've got around 70 reports that we can no longer run. Any help would be GREATLY appreciated!!
 
Dead
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 19 Apr 2010 at 5:02am

(if left (totext({file.date}),1) = "1" then "20", will return just the "20" if the left (totext({file.date}),1) = "1" is true and nothing else (unless I got lost in the logic).  Sometimes it helps to display what values you are getting before trying to convert to another number format (i.e, date).

I also examined the formula and took out a redundant if statement and removed extra paranthesis.  It reads better,  I do not have a way to check it.
 
if len(totext({file.date})) > 10 then date (
  if left (totext({file.date}),1) = "1" then
      "20" & mid (totext ({file.date}),3,2) & "," &
   mid (totext ({file.date}),5,1) &
   mid (totext ({file.date}),7,1) & "," &
   mid (totext ({file.date}),8,2)
   else
    "19" &  mid (totext ({file.date}),3,2) & "," &
    mid (totext ({file.date}),5,1) &
    mid (totext ({file.date}),7,1) & "," &
    mid (totext ({file.date}),8,2)
 
I hope this helps.
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 19 Apr 2010 at 5:03am
Also if you used a variable, you could eliminate the redundant code.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum