4 Replies Latest reply on Apr 15, 2013 2:01 PM by Mike_Mitchell

    Generate Recurring Month function

    nmorales

      Hi All

       

      Im trying to create a script where I can generate a schedule for every 2 months, 3 months or month on the 4th (or whatever day entered)

       

      The problem I am facing is that some months do not have 30 days so if someone enters on the 30th of every month it wont generate it correctly. Does any one have any sample scripts I can see or give me some advise.

       

      Thanks

        • 1. Re: Generate Recurring Month function
          Mike_Mitchell

          Nicole -

           

          The default would be:

           

               Date ( Month ( {startDate} ) + X ; Day ( {startDate} ) ; Year ( {startDate} ))

           

          where X is the number of months you want to add. You'll probably want to add an exception for those cases where, as you say, the user enters a day greater than the target month. That'll depend on the business rules, but, if we assume you want it to be the last day of the month in that case, you would use:

           

               Date ( Month ( {startDate} ) + X + 1 ; 0 ; Year ( {startDate} ))

           

          HTH

           

          Mike

          • 2. Re: Generate Recurring Month function
            taylorsharpe

            We can help with any formula.  But I would like to be clear on what you want to do with say someone who makes a schedule on the 31st of the month and the month they want to schedule it on does not have 31 days.  Do you want it to go the first of the month or the last day of the previous month?  Also, be aware that if you use the function with a day beyond what is in a month, FileMaker will just add it into the next month.  So, Date ( 4 ; 31 ; 2013 ) is actually May 1st, 2013 and FileMaker will show it that way.  So you could do something like Date ( 4 + x ; 31 ; YYYY ) where x is the number of months and it will work mathmatically, but months with 30 days will show the 1st of the next month. 

            • 3. Re: Generate Recurring Month function
              nmorales

              This is helpful.  I was thinking of skipping the month if there is no 30th. so it would go from Jan to March since Feb doesnt have 30days

              • 4. Re: Generate Recurring Month function
                Mike_Mitchell

                In that case, try this:

                 

                Let ( [

                     inputDate = {insert your input date here} ;

                     targetMonth = Month ( inputDate ) + X ;

                     targetDay = Day ( inputDate ) ;

                     targetYear = Year ( inputDate ) ] ;

                 

                Case ( targetMonth <> 2 ; Date ( targetMonth ; targetDay ; targetYear ) ; Date ( 3 ; targetDay ; targetYear ))

                 

                )

                 

                Edit: Note that this will not handle the case where users input the 31st of the month. You'll need additional conditions to handle that.