ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

subst/concat date elements

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

  • subst/concat date elements

    I need to format date variables that will be used to select data between two dates. I can get the current timestamp formatted to my needs, but having issues with the past timestamp. Basically the past timestamp will be the current year/month with day starting at 01. I've tried using subst and concat, as well as dtefmt, but no luck. I keep hitting a brick wall with everything I try (or search for)

    I would go the SQL way, but one of the databases is a System/38 and does not support SQL; from what I understand.

    Any guidance?


    Code:
         D DateISO         S               D
         D year            S              4S 0
         D month           S              2S 0
         D CurrentTS       S              7S 0
         D PastTS          S              7S 0
    
          /free
    
           //Getting date from system and doing some parsing
           DateIso = %Date();
           year    = %SubDt(DateISO: *y);
           month   = %SubDt(DateISO: *M);
    
           //Formatting current timestamp for query
           CurrentTS = %dec(DateISO:*cyMD);
    
           //Formatting past timestamp for query
           PastTS = %subst(CurrentTS:5:0) + '01';
           //PastTS should look like '1121201'
           //                         CYYMMDD
    
           *INLR   = *On;
    
          /end-free

  • #2
    Re: subst/concat date elements

    even a flat file supports SQL, just going to use more Substr.

    But since pastts is just a numeric , just take (Century * 1000000) + (Year * ........) + (01 [for the day])
    now pastts will have what you want.

    Or you could extract the number of days from CurrentTS, then subtract that (-1) from its self giving pastTS. ex 1121227 --> day = 27 --> 27 - 1 = 26 --> 1121227 - 26 = 1121201 (PastTS).
    Hunting down the future ms. Ex DeadManWalks. *certain restrictions apply

    Comment


    • #3
      Re: subst/concat date elements

      Here's one way to get the 1st day of the month.

      Code:
            * Find the first day of month / last day of month
           D StrDate         S               D
           D EndDate         S               D
            /FREE
             StrDate = %date(%subst(%char(%date()):1:8) + '01':*ISO);
             EndDate = StrDate + %months(1) - %days(1);
      
           //  another way to get just the last day of this month
             EndDate = %date() + %month(1) - %subdt(%date() + %month(1):*days);
      
            /END-FREE

      Comment


      • #4
        Re: subst/concat date elements

        Mine is similar to Arrows:

        Code:
        FirstOfMonthDate = Workdate -
                           %days( %subdt( WorkDate : *days )) +
                           %days( 1 );
        You could simply add "1" to the second line and drop the 3rd line altogether, but I find it's more readable this way.

        This routine is tucked away in my Date_S service program, so all I have to do is to perform FirstOfTheMonth = Date_FirstOfTheMonth( SomeDate ) to set the date. (Which is even more readable, and takes up less space in the actual program.)
        Last edited by MichaelCatalani; December 27, 2012, 08:17 PM.
        Michael Catalani
        IS Director, eCommerce & Web Development
        Acceptance Insurance Corporation
        www.AcceptanceInsurance.com
        www.ProvatoSys.com

        Comment

        Working...
        X