ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Date format without separators

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Date format without separators

    Hello all,

    Here's what I hope is an easy one. I have the need to put the current date out in MMDDYY format WITHOUT separators into a file. I've tried using the DATFMT(*MDY) in my H spec and then having a 'd' type field defined and using %date to set it up, but it includes the slashes. I don't think I can tell the DATFMT spec to not have separators (or can I?). So what is my quickest way to get the current date into a MMDDYY format with no separators? Thanks.

  • #2
    Re: Date format without separators

    Code:
    d dec6            s              6  0      
    d char6           s              6         
     /free                                     
       char6 = %char(%date():*MDY0);           
       dec6 = %dec(%date():*MDY);              
       *inlr = *on;

    Comment


    • #3
      Re: Date format without separators

      Rico's code will work, and has a couple of additional lines that aren't needed. Here it is reduced even further:

      Code:
      d Dec6            s              6p 0      
       /free                                    
       
         Dec6 = %dec( %date : *MDY );              
       
         *inlr = *on;
      Michael Catalani
      IS Director, eCommerce & Web Development
      Acceptance Insurance Corporation
      www.AcceptanceInsurance.com
      www.ProvatoSys.com

      Comment


      • #4
        Re: Date format without separators

        I have a solution to this common problem of needing the current date in multiple formats (for flexibility across different programs) which uses a /copy member and a service program. The benefit is that I only need to provide a /copy member in my programs which contains the definition of the prototype describing the signature used for the sub-procedure call invoked by the application program. It also contains the data structure to hold the results so once this solution is established the only thing a program needs is the /copy statement and the procedure call, i.e. ...
        //**************************************************
        // Populate the Time Stamp related data structures
        //**************************************************
        getTimestamp(TimeStamp:CurrentDate:CurrentTime:Sys Date:SysTime:
        tsHHMMSS:tsYYYYMMDD:tsMMDDYYYYateNow_ISOateNow_USA);

        After the call completes, the DS field values will contain the current date in several different formats and the component parts of month, day and year as shown below.

        CURRENTDATE = 2010-11-17

        CURRENTTIME = 09:53 AM

        DATENOW_ISO = 2010-11-17

        DATENOW_USA = 11/17/2010

        DATEUSADS
        TSMMDDYYYYA = 11172010
        TSMMDDYYYY = 11172010.

        SYSDATEDS
        SYSDATE = 20101117.
        SYSTIME = 095313.

        TIMESTAMP = 2010-11-17-09.53.13.946000

        TIMESTAMPISODS
        TSYYYYMMDDA = 20101117
        TSYYYYMMDD = 20101117.
        TSTIMESTAMPA = 20101117095313
        TSTIMESTAMPISO = 20101117095313.
        TSYEAR = 2010.
        TSCC = 20.
        TSYY = 10.
        TSYYMMDD = 101117.
        TSMONTH = 11.
        TSDAY = 17.
        TSHHMMSSA = 095313
        TSHHMMSS = 095313.
        TSHHMM = 0953.
        TSHOUR = 09.
        TSMINUTE = 53.
        TSSECOND = 13.

        The full solution can be viewed here. ( http://onrpgle.wordpress.com/2010/12...vice-programs/ )
        Last edited by kitvb1; December 28, 2010, 01:45 AM. Reason: Disabled smilies in text

        Comment


        • #5
          Re: Date format without separators

          Thanks for posting Ben...

          This would also be another solution

          (look for getdate)

          jamie
          All my answers were extracted from the "Big Dummy's Guide to the As400"
          and I take no responsibility for any of them.

          www.code400.com

          Comment

          Working...
          X