Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Better way to subtract dates from ea other?

Featured Replies

Hello-

I am trying to put together a calculation that will determine how many days it has been since an invoice has been submitted. I tried the following calculation:

DayOfYear ( Get ( CurrentDate ) ) - DayOfYear ( DATE SUBMITTED )

The problem is that it fails when the dates span 2 calendar years.

Is there a better way to write this that will give an exact number of days?

Also is there a way to display the answer in "X months and Y days".

Any help would be greatly apprecitated.

Thank you.

Date Submitted - Get ( CurrentDate) will give you the number of days. After this it gets messy. Months can 28 to 31 days, years can be 365 or 366 days. I had an e-mail from OneStopFileMaker.com that offers "free" custom functions including one to do this. Haven't checked it.

  • Author

One last thing, I have a field called: Invoice PAID whose values are either "Yes" or "No"

is there a way to STOP the calculation of days since submitted once Invoice PAID = Yes :

Thank you very much...

Surfer,

To get the number of days dependent on PAID:

If(PAID = "No", Get( CurrentDate ) - DATE SUBMITTED, "")

For the number of months, subtract the month fields and add 12 times the difference in the years:

Month (Get( CurrentDate )) - Month(DATE SUBMITTED) + 12 * (Year( Get( CurrentDate)) - Year(DATE SUBMITTED))

and the number of days left over is:

Day(Get( CurrentDate)) - Day(DATE SUBMITTED)

Cheers,

John.

Make the field a number with an auto-enter calculation of

Case( Invoice PAID = "No"; DayOfYear ( Get ( CurrentDate ) ) - DayOfYear ( DATE SUBMITTED ); DaysCalc )

where DaysCalc is the name of the field with the auto-enter calc, i.e. *this* field. Click OK and then deselect the 'Do not replace existing value for field' option.

For X Months and Y Days,

( Month( Get ( CurrentDate ) ) - Month( DATE SUBMITTED ) - ( Day( Get ( CurrentDate ) ) < Day( DATE SUBMITTED ) ) ) + (Year( Get ( CurrentDate ) ) - Year( DATE SUBMITTED )) * 12 & " Month" & Left( "s"; ( Month( Get ( CurrentDate ) ) - Month( DATE SUBMITTED ) - ( Day( Get ( CurrentDate ) ) < Day( DATE SUBMITTED ) ) ) + (Year( Get ( CurrentDate ) ) - Year( DATE SUBMITTED )) * 12 <> 1 ) & " and " & Case( Day( Get ( CurrentDate ) ) - Day( DATE SUBMITTED ) >= 0; Day( Get ( CurrentDate ) ) - Day( DATE SUBMITTED ); Date( Month( DATE SUBMITTED ) + 1; Day( DATE SUBMITTED ); Year( Get ( CurrentDate ) ) ) - Date( Month( DATE SUBMITTED ); Day(DATE SUBMITTED ); Year( Get ( CurrentDate ) ) ) + Day( Get ( CurrentDate ) ) - Day( DATE SUBMITTED ) ) & " Day" & Left( "s"; Day( Get ( CurrentDate ) ) - Day( DATE SUBMITTED ) <> 1 )

This assumes that a 'month' is equal to the difference of two consecutive months with the same Day, e.g. 5/7 to 6/7.

Here's a slightly modified version that seems to work more accurately.

Let( m = ( Month( Get ( CurrentDate ) ) - Month( DATE SUBMITTED ) - ( Day( Get ( CurrentDate ) ) < Day( DATE SUBMITTED ) ) ) + (Year( Get ( CurrentDate ) ) - Year( DATE SUBMITTED )) * 12 ; m & " Month" & Left( "s"; m <> 1 ) ) & " and " & Case( Day( Get ( CurrentDate ) ) >= Day( DATE SUBMITTED ); Day( Get ( CurrentDate ) ) - Day( DATE SUBMITTED ); Date( Month( DATE SUBMITTED ) + 1; Day( Get ( CurrentDate ) ); Year( Get ( CurrentDate ) ) ) - Date( Month( DATE SUBMITTED ); Day( DATE SUBMITTED ); Year( Get ( CurrentDate ) ) ) ) & " Day" & Left( "s"; Day( Get ( CurrentDate ) ) - Day( DATE SUBMITTED ) <> 1 )

  • Author

Thank you!

That works brilliantly!

I really appreciate your help...

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.