Brian Dunning's FileMaker Custom Functions

fnOneMonthEarlier ( DateFrom )

Gives the exact date of one month earlier

  Average rating: 4.6 (21 votes) Log in to vote

Maria del Rocio Moguel   Maria del Rocio Moguel
UT MD Anderson Cancer Center

Share on Facebook Share on Twitter

  Sample input:
  Sample output:

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

This function takes into account the different lengths of the months (30, 31, 28) so in case the day number of the DateFrom is 31, it will place the correct day number for the previous month. (It does not take into consideration a leap year; it will use Feb 28).



eos   eos, Teg
Apr 13, 2015
Try letting FM's calc engine do the hard work, incl, figuring out leapyearness:

// Signature: fnOneMonthEarlier_eos ( dateStart )

Let ( [
inputYear = Year ( dateStart ) ;
inputDay = Day ( dateStart ) ;
inputMonth = Month ( dateStart )
] ;
Case (
Month ( Date ( inputMonth - 1 ; inputDay ; inputYear ) ) = inputMonth ;
Date ( inputMonth ; 0 ; inputYear ) ;
Date ( inputMonth - 1 ; inputDay ; inputYear )
Lee Smith   Lee Smith
Apr 13, 2015
I must be missing something here.

Why not just

Date ( Month ( DateFrom ) - 1 ; Day ( DateFrom ) ; Year (DateFrom ) )
Rocio   Rocio, Houston, TX
Apr 13, 2015
Thank you for your comments!

Eos, Teg, I guess there are different ways to get to the same result, but I like yours better because it takes lap year into consideration. Thank you!

Lee Smith, your calculation won't work correctly for months with 31 days. For example if the input is 12/31/2015, the output is 12/1/2015. In this case, I want the output to be 11/30/2015. Thank you.
Bernard Moreau   Bernard Moreau, Belgium, Borchtlombeek
Apr 13, 2015

The year of your Sample Output exemple has to be 2014 isn't it ?
unix   unix, Japan
Apr 13, 2015
Here is another one.
put -1 as months parameter get the result you want.

and simplify it

guess = Date(Month(startDate) + months; Day(startDate); Year(startDate));
guess - Case ( Day (guess) <> Day (startDate) ; Day ( guess ) )
Rocio   Rocio, Houston, TX
Apr 14, 2015
Yes, Bernand Moreau. Thank you for noticing. I corrected it.
Jeep Watson   Jeep Watson, Baltimore, MD
Apr 14, 2015
What is purpose of this function?

Enter 10/31 returns 9/30
Enter 10/30 returns 9/30
Enter 3/31 returns 2/28
Enter 3/30 returns 2/28
Enter 3/29 returns 2/28

Lesser days do return the same day in the prior month.
I just don't see a practical use. Explain.
Rocio   Rocio, Houston, TX
Apr 15, 2015
Jeep Watson, I created the function because I need to send some paperwork one month before the due date (not just 30 days each time). If the due date is October 31 or October 30, the function will give me September 30 because September only has 30 days. It would be incorrect to have 9/31. The same happens for March; if the due date is the last day of March, I have to send the paperwork the last day of February, which only has 28 days.
This function may not be useful for you if you don't have a similar scenario, but at least, it works for my situation.
Thank you for your comments.
Samuel   Samuel, k9ZgA5ytGf
Nov 27, 2015
Hi, I would like to keep the invitations in my inbox so that I can later secarh & find them. (otherwise, we will need a secarh engine which also indexes the calendar).In current v3.1.3, when I accept an invitation, it is deleted from my inbox. I could not find an option not to do it (Outlook has such an option).Thanks.

Log in to post comments.


Note: these functions are not guaranteed or supported by Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 16 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: