[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

Date and Time Conversion from Simple Numeric Fields

We have just started using Crystal Report 9.0 interfacing data using IBM Client Access ODBC for AS400 DB2. We have defined date and time field in simple numeric field such as 20060403 and 1200 for 04/03/06 and 12:00AM respectively.  We would like to show the date and time in converted manner at Crystal Report.  Is there any simple conversion technique to print them without changing AS400 database format?
Please advise me.
0
Yukiwase
Asked:
Yukiwase
  • 3
1 Solution
 
dylanyeeCommented:
There is no simple conversion from CR that suit your format, but you could create a formula to achieve this, this is my example:

numbervar theDate := 20060403;
numbervar theTime := 1200;
stringvar strDate;
stringvar strTime;
numbervar theYear;
numbervar theMonth;
numbervar theDay;
numbervar theHour;
numbervar theMin;

strDate := TOTEXT(theDate,0,"");
strTime := TOTEXT(theTime,0,"");

theYear := TONUMBER(LEFT(strDate, 4));
theMonth := TONUMBER(MID(strDate, 5, 2));
theDay := TONUMBER(RIGHT(strDate, 2));
theHour := TONUMBER(LEFT(strTime, 2));
theMin := TONUMBER(RIGHT(strTime, 2));

CDATETIME(theYear, theMonth, theDay, theHour, theMin, 0);

dylan
0
 
janmariniCommented:


Another way would be to use this formula field:

to TEST display of the date field using a hard-coded variable:

Local StringVar myDate := "20060403";
totext(cdate(picture(myDate,"xxxx/xx/xx")),"MM/dd/yyyy")

to use your date field the syntax would be:

totext(cdate(picture({yourDateFieldName},"xxxx/xx/xx")),"MM/dd/yyyy")

0
 
dylanyeeCommented:
janmarini's suggestion is better ;)

dylan
0
 
dylanyeeCommented:
glad I could help~

dylan
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now