Table of contents
1.
Introduction
2.
Excel Days Function
2.1.
EXAMPLES
2.2.
Points to Note
3.
Excel Month Function
3.1.
Examples
4.
EOMONTH Function (last day of the month in Excel)
4.1.
Examples
4.2.
Points to Note
5.
Excel Year Function
5.1.
Examples
5.2.
Points to Note
6.
FAQs
7.
Key Takeaways
Last Updated: Mar 27, 2024
Easy

Days, Month and Year Function

Author Komal Shaw
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

The Excel Days function is a Date/Time Function. It tells the number of days between a start date and the end date.

The Excel Month function returns the month from date, i.e., it returns the month number ranging from 1-12(Jan - Dec).

The Excel Year function extracts a year number from a given date, i.e., it returns the year component of a given date as a 4-digit number.

In this article, we are going to learn in detail all the three functions of excel, Days, Month, and Year Function.

Excel Days Function

Let there be a starting date A1 and an ending date E1.

=DAYS(E1, A1) will return the number of days between the two dates.

The purpose of using this function is to get the days between two dates.

The Return Value is a number representing the days.

SYNTAX -  

=DAYS(endDate, startDate)

ARGUMENTS - 

startDate(the starting date) and endDate(the ending date).

Both the start and end dates must be valid Excel dates. They can also be text values that can be parsed as dates. They should be whole numbers and not fractional values.

The Days function will return a negative value if we reverse the start and end dates.

Therefore, =DAYS(E1, A1) = E1-A1

EXAMPLES

  1. =DAYS("15-Jun-21", "1-Jun-21")
    //the function will return 14.
  2. If we want to include both the starting and ending date, increase the count by 1.
    =DAYS("2-Jun-21", "1-Jun-21")+1
    //this will return 2

Points to Note

  1. We should avoid storing or parsing dates represented by text values because it might produce errors. Thus it is better to work with native Excel dates.
  2. The Excel Days function works only with whole numbers.
  3. If the Days function can't recognize any date, it will return #VALUE! error.
  4. If the dates are out of range, it will return #NUM! error.

Excel Month Function

The Excel Month function returns the month from date, i.e., it returns the month number ranging from 1-12(Jan - Dec).

We can do many valuable things using this Excel Month function.

The purpose of this function is to get the month as a number(1-12) from a given date.

The return value is a number between 1-12.

SYNTAX -

"=MONTH(serialNumber)"

ARGUMENTS -

serialNumber, which should be a valid Excel date.

Examples

  1. =MONTH(“15-Jul-2018”)
    //returns 7
  2. =MONTH(“20-Dec-2021”)
    //returns 12
  3. =MONTH(TODAY())
    //returns the number of the current month

EOMONTH Function (last day of the month in Excel)

The Excel EOMONTH function is used to get the last day of a month based on the given startDate.

SYNTAX -

"=EOMONTH(startDate, months)"

ARGUMENTS

startDate is the starting date or a reference to a cell having the starting date.

Months refer to the number of months before or after the starting date. Positive values are used for future dates, and negative values are used for past dates.

Examples

  1. =EOMONTH(A1, 1)
    //this will return the last day of the month, one month after the date in cell A1.
  2. =EOMONTH(A1, -1)
    //this will return the last day of the month, one month before the date in cell A1.
  3. =EOMONTH(TODAY(), 0)
    //this will return last day of the current month
  4. =EOMONTH(TODAY(), 0)-TODAY()
    //this will return the number of days left till the end of the current month.

Points to Note

  1. The serialNumber should be a valid Excel date.
  2. If any date is not recognized, the MONTH function will return #VALUE! error.
  3. If any date is supplied as a number out of range, the MONTH function will return #NUM! error.

Excel Year Function

The Excel Year function extracts a year number from a given date, i.e., it returns the year component of a given date as a 4-digit number.

The purpose of this function is to get the year from a given date.

The return value is a 4-digit number that represents a year.

SYNTAX-

"=YEAR(date)"

ARGUMENTS-

The date should be a valid Excel date.

Examples

  1. =YEAR(“25-JAN-2016”)
    //returns 2016
  2. =YEAR(“12-FEB-2022”)
    //returns 2022

Points to Note

  1. The date should be a valid excel date.
  2. If there is any text value as input, the YEAR function will return the #VALUE error.

FAQs

  1. What are the arguments of DAYS function?
    Start date and end date.
     
  2. What are the arguments of MONTH and YEAR functions?
    Only a valid Excel Date.
     
  3. What are the arguments of the EOMONTH function?
    A starting date and a month input.
     
  4. What error is thrown by the MONTH function if the date is not recognized?
    #VALUE! error
     
  5. What are positive values used as in the MONTH argument?
    Positive Values are used for future dates. 

Key Takeaways

In this article, we have extensively discussed Excel's DAYS, MONTH, EOMONTH, and YEAR functions.

We hope that this blog has helped you enhance your knowledge regarding these functions.

If you want to learn more, check out our articles on Days and DATEDIF FunctionHLOOKUP FunctionToday and Now Function.

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. 

Enrol in our courses and refer to the mock test and problems available.

Take a look at the interview experiences and interview bundle for placement preparations.

Do upvote our blog to help other ninjas grow. 

Happy Coding!

Live masterclass