How to use the DATE function
What is the DATE function?
The DATE function returns a number that acts as a date in the Excel environment.
Table of Contents
- Introduction
- Excel function syntax
- Function arguments
- DATE Function Example
- Add or subtract months and days
- Date function example
- What does the Date function do?
- Date function format
- Date function not working
- How to make Excel order by date
- Date function add days
- Date function subtract days
- Date function add months
- Last day of a given month
- Get Excel file
- Calculate date given weekday and week number (week starts on Sunday)
- Calculate date given weekday and week number (week starts on Monday)
1. Introduction
What is an Excel date?
Dates are stored numerically but formatted to display in human-readable date/time formats, this enables Excel to do work with dates in calculations.
For example, dates are stored as sequential serial numbers with 1 being January 1, 1900 by default. The integer part (whole number) represents the date the decimal part represents the time.
This allows dates to easily be formatted to display in many date/time formats like mm/dd/yyyy, dd/mm/yyyy and so on and still be part of calculations as long as the date is stored numerically in a cell.
You can try this yourself, type 10000 in a cell, press CTRL + 1 and change the cell's formatting to date, press with left mouse button on OK. The cell now shows 5/18/1927.
2. DATE Function Syntax
DATE(year, month, day)
3. DATE Function Arguments
year | A number equal or higher than 1900. |
month | A number between 1 (January) and 12 (December). You can use larger numbers as well. |
day | A number between 1 and 31 based on the number of days in the month specified in argument month. |
4. DATE Function Example
The image above shows you the DATE function in column E. It uses three arguments, the first argument is the year found in column B.
The second argument is the month, shown in column C. Note that you need to use a number for the month.
The third argument is the day of the month, displayed in column D. Make sure you enter the correct day for the month, keep in mind most months have 30 days or 31 days. February has 28 days except for leap years that have 29 days.
5. Add or subtract months and days
If you use a month number larger than 12, for example 13, DATE(2009,13,1) the DATE function returns 1/1/2010. Month number zero returns the previous month.
The same thing happens with a day number that is larger than 31 or smaller than 1.
You can use that to do dynamic date series or do date-based calculations.
6. Date function example
The image above demonstrates the date function in column E, it uses values from column B, C and D.
Formula in cell F3:
7. What does the Date function do?
The DATE function returns an Excel date that you can use in formulas, Excel can't calculate dates in formulas unless you reference a cell containing an Excel date or create an Excel date using the DATE function.
Hardcoding dates in a formula are not possible, use the DATE function to create an Excel date.
Why is that?
Excel uses numbers formatted as dates, 1 is 1/1/1900, and 1/1/2000 is 36526.
Prove it?
Sure, type 1 in a cell and press Enter. Select the cell and press CTRL + 1 to format the cell.
A dialog box appears, select Date in Category: and press the "OK" button.
Number 1 is now formatted as an Excel date, the cell shows 1/1/1900.
8. Date function format
The animated image above shows you the "Format Cells" dialog box, it allows you to choose from many different date formatting types. Here is how:
- Select the cell.
- Press CTRL + 1 to open the "Format Cells" dialog box.
- Select Date in the Category:, see the image above.
- Pick a formatting type.
- Press with left mouse button on "OK" button to apply changes.
You can also use the TEXT function to format dates.
Formula in cell B2:
Explaining formula in cell B2
Step 1 - Create an Excel date
The DATE function calculates a serial number that represents a specific date based on three arguments. Year, month, and day.
DATE(year, month, day)
DATE(1900, 1, 1)
returns 1.
Step 2 - Return a number formatted as a date
The TEXT function formats a cell value based on given placeholder characters.
TEXT(value, format_text)
TEXT(DATE(1900, 1, 1), "d-m-yyyy")
becomes
TEXT(1, "d-m-yyyy")
and returns 1-1-1900.
9. Date function not working
- Did you spell the DATE function correctly?
Excel returns a #NAME? error if you didn't. - Check the arguments, they must be numerical. Text is not allowed.
Excel returns a #VALUE! error if any of the arguments contain a text value.
year - a number equal or larger than 0 (zero)
month - any number positive or negative
day - any number positive or negative - Did you use exactly three arguments?
Excel returns a dialog box: You've entered too many arguments for this function.
DATE(year, month, day) - Excel Date function returns the wrong date.
If you try a year before 1900 Excel returns a date that you probably didn't expect. Here is how Excel came up with that date. 1900+1800 = 1/1/3700 - The DATE function returns hashtags.
The DATE function can't return dates before 1/1/1900. The formula in cell B2 above tries to calculate an Excel date before 1/1/1900.
10. How to make Excel order by date
The image above shows a list of dates in column B, here is how to sort the dates.
- Press with right mouse button on any date in column B.
A popup menu appears.
- Press "Sort". Another popup menu appears.
- Press either "Sort Oldest to Newest" or "Sort Newest to Oldest".
Here is how to sort the dates using a formula.
Formula in cell D2:
Explaining formula in cell D2
Step 1 - Create a sequence of values from 1 to n
The ROWS function returns a number based on the number of rows in a cell reference.
ROWS(ref)
ROWS($A$1:A1)
returns 1.
Step 2 - Extract k-th largest serial number
The LARGE function calculates the k-th largest number.
LARGE(array, k)
LARGE($B$2:$B$17, ROWS($A$1:A1))
becomes
LARGE($B$2:$B$17, 1)
becomes
LARGE({45338; 53253; 49446; 51878; 48237; 52238; 44437; 53971; 49050; 47745; 45727; 45027; 49156; 49329; 48599; 49590}, 1)
and returns 53971 (10/6/2047) in cell D2.
11. Date function add days
The formula in cell C3 adds 10/25/2024 with 10 days specified in cell B3.
Formula in cell C3:
Explaining formula in cell C3
Step 1 - Add dates
The plus sign lets you add numbers in Excel formulas.
25+B3
becomes
25 + 10 equals 35.
Step 2 - Calculate serial number representing an Excel date
The DATE function calculates a serial number that represents a specific date based on three arguments. Year, month, and day.
DATE(year, month, day)
DATE(2024,10,25+B3)
becomes
DATE(2024,10,35)
and returns 45600 formatted as 11/4/2024 in cell C3.
12. Date function subtract days
The formula in cell C3 subtracts 10/25/2024 with 10 days specified in cell B3.
Formula in cell C3:
Explaining formula in cell C3
Step 1 - Subtract dates
The minus sign lets you subtract numbers in Excel formulas.
25-B3
becomes
25 - 10 equals 15.
Step 2 - Calculate serial number representing an Excel date
The DATE function calculates a serial number that represents a specific date based on three arguments. Year, month, and day.
DATE(year, month, day)
DATE(2024,10,25-B3)
becomes
DATE(2024,10,15)
and returns 45580 formatted as 11/4/2024 in cell C3.
13. Date function add months
The formula in cell E3 adds months based on the number in cell B3 to a date specified in cell C3.
Formula in cell C3:
Explaining formula in cell C3
Step 1 - Calculate year
The YEAR function returns a number representing the year based on an Excel date (serial number).
YEAR(serial_number)
YEAR(C3)
becomes
YEAR(1/14/2024)
becomes
YEAR(45305)
and returns 2024.
Step 2 - Calculate month
The MONTH function returns a number representing a month. 1 - January, ..., 12 - December.
MONTH(serial_number)
MONTH(C3)+B3
becomes
MONTH(45305)+10
becomes
1+10 equals 11.
Step 3 - Calculate day
The DAY function returns a number representing the day from an Excel date (serial number).
DAY(C3)
becomes
DAY(45305)
and returns 14.
Step 4 - Calculate date
The DATE function calculates a serial number that represents a specific date based on three arguments. Year, month, and day.
DATE(year, month, day)
DATE(YEAR(C3), MONTH(C3)+B3, DAY(C3))
becomes
DATE(2014, 11, 14)
and returns 45610 (11/14/2024).
14. Last day of a given month
The formula in cell D3 calculates the last day for a given month based on a date in cell B3. The date is 1/1/2024, the last day in January 2024 is 31.
The way this works is that the formula adds one month to the date in cell B3 then subtracts with 1 to get the last date of the previous month.
Formula in cell C3:
Explaining formula in cell C3
Step 1 - Calculate year
The YEAR function returns a number representing the year based on an Excel date (serial number).
YEAR(serial_number)
YEAR(B3)
becomes
YEAR(1/1/2024)
becomes
YEAR(45292)
and returns 2024.
Step 2 - Calculate month
The MONTH function returns a number representing a month. 1 - January, ..., 12 - December.
MONTH(serial_number)
MONTH(B3)+1
becomes
MONTH(45292)+1
becomes
1+1 equals 2.
Step 3 - Calculate day
The DAY function returns a number representing the day from an Excel date (serial number).
DAY(B3)
becomes
DAY(45292)
and returns 1.
Step 4 - Calculate the date
The DATE function calculates a serial number that represents a specific date based on three arguments. Year, month, and day.
DATE(year, month, day)
DATE(YEAR(B3),MONTH(B3)+1,1)-1
becomes
DATE(2014, 2, 1)-1
becomes
45323-1
and returns 45322 (1/31/2024).
15. Get Excel file
16. Calculate date given weekday and week number (week starts on Sunday)
This section demonstrates formulas that returns a date based on a week number and a weekday like Sun to Sat. It uses the current year to calculate the date.
La Thăng asks:
I want to find the day if given date and week, for example: if given Tuesday, 32nd week, 2015 >>> how to create a formula to point out 4/8/2015?
Formula in cell D6:
Explaining formula in cell D6
Step 1 - Calculate the first date of this year
The TODAY function returns today's date, the function is volatile meaning it recalculates every time you enter a value in a cell and press enter or press F9.
TODAY() returns 5/8/21.
Step 2 - Calculate the first date of this year
The YEAR function returns the year based on an Excel date.
YEAR(TODAY())
becomes
YEAR(44324)
and returns 2021.
Step 3 - Calculate the first date of this year
The DATE function returns an Excel date based on a year number, month number and day number.
DATE(year, month, day)
Year is a number from 1900 to 9999, month is a number from 1 to 12. 1 = January, ... , 12 = December. Day is usually a number between 1 and 31 but can be larger.
DATE(YEAR(TODAY()), 1, 1)
becomes
DATE(2021, 1, 1)
and returns 44197.
Step 4 - Subtract with the corresponding weekday number
The WEEKDAY function converts an Excel date to a number ranging from 1 to 7, based on when the week begins.
WEEKDAY(serial_number, [return_type])
If you live in the US the week in starts on Sundays, return_type is 1.
WEEKDAY(DATE(YEAR(TODAY()), 1, 1), 1)
becomes WEEKDAY(44197, 1)
and returns 6. 44197 is 1/1/2021 and that day is a Friday.
1 - Sunday, ... , 7 - Saturday.
Step 5 - Subtract date with weekday number
DATE(YEAR(TODAY()), 1, 1)-WEEKDAY(DATE(YEAR(TODAY()), 1, 1), 1)
becomes
44197 - 6 equals 44191.
Step 6 - Calculate and add the number of days from Monday/week 1 to Monday/(nth week -1)
+7*(D4-1)
Example, 7*(32-1)
becomes
7*31 and returns 217.
Step 7 - Calculate and add weekday number
The MATCH function returns the relative position of the given item in a cell range or array.
MATCH($D$4, {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}, 0)
If you week begins on sunday, this is the array you want to be using:
{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}.
Example, "Tue" returns 3. "Tue" is in position three in the array.
Step 8 - Add and subtract
44192+217+2 = 44411
44411 is 8/3/2021.
17. Calculate date given weekday and week number (week starts on Monday)
This example demonstrates a formula that works with weeks that begin with Mondays.
Formula in cell 5:
Note that the WEEKDAY function uses 2 in the second argument meaning the week begins with a Monday and the array in the second argument in the MATCH function begins with Monday.
Tip! You can shrink the formula if you can convert the weekday to a number yourself.
'DATE' function examples
This article describes how to count unique distinct values. What are unique distinct values? They are all values but duplicates are […]
Table of Contents Excel monthly calendar - VBA Calendar Drop down lists Headers Calculating dates (formula) Conditional formatting Today Dates […]
Table of contents Filter unique distinct row records Filter unique distinct row records but not blanks Filter unique distinct row […]
Functions in 'Date and Time' category
The DATE function function is one of 22 functions in the 'Date and Time' category.
Excel function categories
Excel categories
One Response to “How to use the DATE function”
Leave a Reply
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form
Hi
I would just use =eomonth(b3)
Much simpler