× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hello GA,

> Wishing to not have to reinvent a wheel that's probably been invented
> several times. If someone has a link that solves my dilemna, I'd really
> appreciate it.  If I end up having to write it myself, I'll gladly
> share.

Yes, it's been invented many times.  In fact, IBM even invented it when
they created the system APIs.


> I am getting a text file whose records contain dates like "October 08, 2002"
> (without quotes), and need to convert these dates to an *ISO date.
>
> Also, anybody have a quick conversion for "m/d/yyyy" dates, where the
> month may be 1 or 2 digits and same with the day of the month?

The CEEDAYS() API can be given an arbitrary "picture string" to tell it
how to interpret the input of a date.  It returns it's result as a lilian
date.   The CEEDATE() API can be used to convert a lilian date to an
arbitrary character string, again using a "picture string."

The documentation for these is in the "Date and Time APIs" section of the
ILE CEE APIs manual:
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/apis/ile1a1.htm

Here's some sample code that demonstrates them:

     H DFTACTGRP(*NO)

      *
      *  API to parse a character date into lilian format
      *
     D CEEDAYS         PR                  opdesc
     D   char_date                   80A   const options(*varsize)
     D   date_format                 80A   const options(*varsize)
     D   lilian_date                 10I 0
     D   feedback                    12A   options(*omit)

      *
      *  API to create character date from lilian format
      *
     D CEEDATE         PR                  opdesc
     D   lilian_date                 10I 0 const
     D   date_format                 80A   const options(*varsize)
     D   char_date                   80A   options(*varsize)
     D   feedback                    12A   options(*omit)

     D fmt1            c                   'Mmmmmmmmmz ZD, YYYY'
     D fmt2            c                   'ZM/ZD/YYYY'
     D iso             c                   'YYYYMMDD'

     D mydate          s             50A
     D temp            s              8A
     D lil             s             10I 0
     D DateFld         s               D


      **  Test parsing date w/leading zero in month.
      **  DateFld should result in 2002-10-08
      **
     c                   eval      mydate = 'October 08, 2002'
     c                   callp     CEEDAYS(mydate: fmt1: lil: *omit)
     c                   callp     CEEDATE(lil: iso: temp: *omit)
     c                   eval      DateFld = %date(temp: *ISO0)
     c                   dsply                   DateFld

      **
      **  Same date w/out leading zero.
      **
     c                   eval      mydate = 'October 8, 2002'
     c                   callp     CEEDAYS(mydate: fmt1: lil: *omit)
     c                   callp     CEEDATE(lil: iso: temp: *omit)
     c                   eval      DateFld = %date(temp: *ISO0)
     c                   dsply                   DateFld

      **
      **  let's try a different date w/a shorter month name
      **
     c                   eval      mydate = 'May 21, 1999'
     c                   callp     CEEDAYS(mydate: fmt1: lil: *omit)
     c                   callp     CEEDATE(lil: iso: temp: *omit)
     c                   eval      DateFld = %date(temp: *ISO0)
     c                   dsply                   DateFld

      **
      **  you can also go the other way, of course.  This formats
      **  todays date nicely.
      **
     c                   eval      temp = %char(%date(): *ISO0)
     c                   callp     CEEDAYS(temp: iso: lil: *omit)
     c                   callp     CEEDATE(lil: fmt1: mydate: *omit)
     c                   dsply                   MyDate

      **
      **  Then there's the good ol' slash date format
      **
     c                   eval      mydate = '01/01/2004'
     c                   callp     CEEDAYS(mydate: fmt2: lil: *omit)
     c                   callp     CEEDATE(lil: iso: temp: *omit)
     c                   eval      DateFld = %date(temp: *ISO0)
     c                   dsply                   DateFld

      **
      **  It also works without the leading zeroes
      **
     c                   eval      mydate = '2/2/2004'
     c                   callp     CEEDAYS(mydate: fmt2: lil: *omit)
     c                   callp     CEEDATE(lil: iso: temp: *omit)
     c                   eval      DateFld = %date(temp: *ISO0)
     c                   dsply                   DateFld

      **
      **  This one, however, will fail...
      **  (it pukes on the extra space before the 1)
      **
     c                   eval      mydate = 'September  1, 2004'
     c                   callp     CEEDAYS(mydate: fmt1: lil: *omit)
     c                   callp     CEEDATE(lil: iso: temp: *omit)
     c                   eval      DateFld = %date(temp: *ISO0)
     c                   dsply                   DateFld


     c                   eval      *inlr = *on

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.