ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Determining the first day & Last day of Month

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

  • Determining the first day & Last day of Month

    Does anyone have code that will help me determine what the first day and last day of the month? I am creating a report that lists items in the month that the report was generated. I know I can get the first day of the month but the ending date might be a little tricky.

    DAC

  • #2
    Re: Determining the first day & Last day of Month

    Hi dcutaia:

    Nice thread here on that subject


    Best of Luck
    GLS
    The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

    Comment


    • #3
      Re: Determining the first day & Last day of Month

      Here is what I use...

      Thirty days has September, April, June, and November. All the rest have thirty one except February.

      Now you know that the first day of each month is 1. And this little jingle tells you that some are 28, 30 and 31. Ohh and don't forget that February can also be 29 if YY%4=0
      Your future President
      Bryce

      ---------------------------------------------
      http://www.bravobryce.com

      Comment


      • #4
        Re: Determining the first day & Last day of 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);
        
               *INLR = *on;
              /END-FREE

        Comment


        • #5
          Re: Determining the first day & Last day of Month

          if you cant use last_day in sql then this will work

          Code:
          d Firstday        s              6  0           
          d lastday         s              6  0           
                                                          
           /free                                          
                                                          
             Firstday = %dec(                             
                        (%date() -                        
                        %days(%subdt(%date():*days)) +    
                        %days(1) )                        
                        :*MDY);                           
                                                          
                                                          
             lastday =  %dec(                             
                        (%date() +                        
                        %months(1)) -                     
                        %days(%subdt((%date() +           
                        %months(1)):*days))               
                        :*mdy);                           
          
                                       
              *inlr = *on;             
           /end-free
          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


          • #6
            Re: Determining the first day & Last day of Month

            Arrow wins . . .
            Greg Craill: "Life's hard - Get a helmet !!"

            Comment


            • #7
              Re: Determining the first day & Last day of Month

              Thanks a bunch. That was really helpful.

              DAC

              Comment

              Working...
              X