Comment utiliser la fonction EOMONTH dans Google Sheets ?

Les EOMONTH function in Google Sheets stands for “End Of MOIS“, and rightly so. It returns the last calendar date of a month that is a specified number of months behind or ahead of a given date.

Syntaxe

=EOMONTH(start_date, months)
  • date_début – is the date that the EOMONTH function calculates the last date of a month from.
  • mois – is the number of months that the function should move either in forward or backward in time, corresponding to a positive value or a negative value respectively.

How to use the EOMONTH function

I’ll demonstrate the function using a few examples. Please consider the snapshot below.

Note that the Result column has been formatted to “dd-mmm-yyyy” for the purposes of avoiding ambiguity (given that the date notations varies across countries).

eomonth-function-google-sheets-1

In the first example case, the start_date parameter takes in the output that the DATE() function returned. And I have set the months parameter to ‘0’, meaning that the function will not move the date forward or backwards in time. Therefore, the function evaluates the end date within the month to 31-Mar-2020.

Let’s take a look at the second case. At the time of writing, the date was 14-Nov-2020 (which the TODAY() function evaluated to in the second example). Factoring a shift of 15 days added to the TODAY() function, along with a value of 12 for months parameter, gives the last date of the month as 30-Nov-2021.

The third example is pretty similar, except for the start_date parameter I provided a reference to the cell that has a date.

Unlike the previous three cases, the start_date for the fourth case is an absolute number. I also keyed in a negative value for the months parameter. The EOMONTH function calculates the last date by shifting the time from the date value 42,846 (equivalent to 21-Apr-2017) back by nine months.

39

Automatiser les transferts de données entre les feuilles de calcul

Découvrez comment

Cas d'intérêt

Poussons l'expérience un peu plus loin et saisissons des valeurs de date basées sur du texte pour la rubrique date_début paramètre.

eomonth-function-google-sheets-2

In the first example, the function trims the decimal values and uses only the integer values. Accordingly, it evaluates the last date of the month. Of course, it cannot accept negative numbers, as there is no date interpretation for such values.

From the next three examples, you can see that the EOMONTH function accepts input date strings in the “dd-mmm-yyyy” and “dd-mm-yyyy” formats. But it will generate an error with “mm-dd-yyyy” date format strings.

Use case: BOMONTH anybody?

Is there a counterpart to EOMONTH, something like BOMONTH (that stands for Beginning Of MOIS)? Apparently, no! But fortunately, you can make use of the EOMONTH function to build a virtual BOMONTH function, as shown in the snapshot below.

eomonth-function-google-sheets-3

In this example, I’ve added a +1 at the end of the function. This adds 1 day, pushing the date from the last day of the month to the first day of the next month. Because this takes the date to the next month, you also have to add -1 as the months parameter. This will shift the function back 1 month, and give you the date of the first day of the current month. The formula here is =EOMONTH(TODAY(),-1)+1.

Use case: last Monday of the month

Since the work week is typically Monday to Friday, it can be helpful in some cases to be able to find the last Monday of every month. In the screenshot below, I’ve done just that.

eomonth-function-google-sheets-4

The WEEKDAY function is used here to get the day of the week that the last day of the month falls on. I’ve used numbers 1 through 7 (1 being Monday, 2 is Tuesday, etc.). By subtracting the weekday and adding 1, you can get the last Monday of the month. The formula for this is =EOMONTH(“5-Dec-2020”,0)-(WEEKDAY(EOMONTH(“5-Dec-2020”,0),2))+1.

If we need to know the date of a specified number of months before or after a given date, we use the EDATE function in Google Sheets.

Note de la rédaction: Il s'agit d'une version révisée d'un article précédent qui a été mis à jour pour plus de précision et d'exhaustivité.

Vous pouvez aussi aimer...

Fonctionnalités et formules de google sheets

Comment calculer le taux d'intérêt nominal à l'aide de Google Sheets ?

Sarah est une jeune professionnelle qui doit prendre des décisions financières importantes. Des cartes de crédit aux hypothèques, en passant par les prêts étudiants et les...
Fonctionnalités et formules de google sheets

Extraire les données de Google Calendar dans Google Sheets à l'aide d'Apps Script

Cet article a été publié à l'origine dans notre forum communautaire. Objectif : Ce guide montre comment utiliser Google Apps Script pour extraire des données...
Fonctionnalités et formules de google sheets

Utilisation de la fonction PROPER pour mettre en majuscule la première lettre de chaque mot dans Google Sheets

Note : Cet article a été publié à l'origine dans notre forum communautaire. Vous avez déjà eu besoin de nettoyer une liste de noms, de titres ou d'autres...