Date and Time Conversion from Simple Numeric Fields

Posted on 2006-04-04
Last Modified: 2008-01-09
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.
Question by:Yukiwase
    LVL 8

    Accepted Solution

    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);

    LVL 7

    Expert Comment


    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";

    to use your date field the syntax would be:


    LVL 8

    Expert Comment

    janmarini's suggestion is better ;)

    LVL 8

    Expert Comment

    glad I could help~


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
    Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now