From and to dates in excel

Add or subtract days from a date

Suppose that a bill of yours is due on the second Friday of each month. You want to transfer funds to your checking account so that those funds arrive 15 calendar days before that date, so you’ll subtract 15 days from the due date. In the following example, you’ll see how to add and subtract dates by entering positive or negative numbers. 

Add or subtract days from a date with =A2+B2, where A2 is a date, and B2 is the number of days to add or subtract.

  1. Enter your due dates in column A.

  2. Enter the number of days to add or subtract in column B. You can enter a negative number to subtract days from your start date, and a positive number to add to your date.

  3. In cell C2, enter =A2+B2, and copy down as needed.

Add or subtract months from a date with the EDATE function

You can use the EDATE function to quickly add or subtract months from a date.

The EDATE function requires two arguments: the start date and the number of months that you want to add or subtract. To subtract months, enter a negative number as the second argument. For example, =EDATE(«9/15/19»,-5) returns 4/15/19.

Use EDATE to add or subtract months from a date. In this case, =EDATE(A2,B2) where A2 is a date, and B2 has the number of months to add or subtract.

  1. For this example, you can enter your starting dates in column A.

  2. Enter the number of months to add or subtract in column B. To indicate if a month should be subtracted, you can enter a minus sign (-) before the number (e.g. -1).

  3. Enter =EDATE(A2,B2) in cell C2, and copy down as needed.

    Notes: 

    • Depending on the format of the cells that contain the formulas that you entered, Excel might display the results as serial numbers. For example, 8-Feb-2019 might be displayed as 43504.

    • Excel stores dates as sequential serial numbers so that they can be used in calculations. By default, January 1, 1900 is serial number 1, and January 1, 2010 is serial number 40179 because it is 40,178 days after January 1, 1900.

    • If your results appear as serial numbers, select the cells in question and continue with the following steps:

      • Press Ctrl+1 to launch the Format Cells dialog, and click the Number tab.

      • Under Category, click Date, select the date format you want, and then click OK. The value in each of the cells should appear as a date instead of a serial number.

Add or subtract years from a date

In this example, we’re adding and subtracting years from a starting date with the following formula:

=DATE(YEAR(A2)+B2,MONTH(A2),DAY(A2))

Add or subtract years from a starting date with =DATE(YEAR(A2)+B2,MONTH(A2),DAY(A2))

How the formula works:

  • The YEAR function looks at the date in cell A2, and returns 2019. It then adds 3 years from cell B2, resulting in 2022.

  • The MONTH and DAY functions only return the original values from cell A2, but the DATE function requires them.

  • Finally, the DATE function then combines these three values into a date that’s 3 years in the future — 02/08/22.

Add or subtract a combination of days, months, and years to/from a date

In this example, we’re adding and subtracting years, months and days from a starting date with the following formula:

=DATE(YEAR(A2)+B2,MONTH(A2)+C2,DAY(A2)+D2)

Use the DATE function to add or subtract years, months, or days to/from a date.

How the formula works:

  • The YEAR function looks at the date in cell A2, and returns 2019. It then adds 1 year from cell B2, resulting in 2020.

  • The MONTH function returns 6, then adds 7 to it from cell C2. This gets interesting, because 6 + 7 = 13, which is 1-year and 1-month. In this case, the formula will recognize that and automatically add another year to the result, bumping it from 2020 to 2021.

  • The DAY function returns 8, and adds 15 to it. This will work similarly to the MONTH portion of the formula if you go over the number of days in a given month.

  • The DATE function then combines these three values into a date that is 1 year, 7 months, and 15 days in the future — 01/23/21.

Here are some ways you could use a formula or worksheet functions that work with dates to do things like, finding the impact to a project’s schedule if you add two weeks, or time needed to complete a task.

Let’s say your account has a 30-day billing cycle, and you want to have the funds in your account 15 days before the March 2013 billing date. Here’s how you would do that, using a formula or function to work with dates.

  1. In cell A1, type 2/8/13.

  2. In cell B1, type =A1-15.

  3. In cell C1, type =A1+30.

  4. In cell D1, type =C1-15.

    cakculate date

Add months to a date

We’ll use the EDATE function and you’ll need the start date and the number of months you want to add. Here’s how to add 16 months to 10/24/13:

use EDATE formula to add months to a date

  1. In cell A1, type 10/24/13.

  2. In cell B1, type =EDATE(A1,16).

  3. To format your results as dates, select cell B1. Click the arrow next to Number Format, > Short Date.

Subtract months from a date

We’ll use the same EDATE function to subtract months from a date.

Type a date in Cell A1 and in cell B1, type the formula =EDATE(4/15/2013,-5).

Subtract months from a date

Here, we’re specifying the value of the start date entering a date enclosed in quotation marks.

You can also just refer to a cell that contains a date value or by using the formula =EDATE(A1,-5)for the same result.

More examples

To add years to or subtract years from a date

Adding and subtracting dates examples

Start Date

Years added or subtracted

Formula

Result

10/24/2013

3 (add 3 years)

=DATE(YEAR(A2)+B2,MONTH(A2),DAY(A2))

10/24/2016

10/24/2013

-5 (subtract 5 years)

=DATE(YEAR(A4)+B4,MONTH(A4),DAY(A4))

10/24/2008

To generate a DateTime sequence in Excel, we can use the SEQUENCE function with the DATE function. We will see how to do that.

But if you want the sequence of date and time separately, we may also require the MOD, INT, and TIME functions.

The formulas below apply to Excel 365 as it uses the SPILL feature and SEQUENCE function, which may not be available in other versions.

You may already know how to generate a sequence of dates in Excel. If not, here it is.

Excel Formula # 1:

=DATE(2022,1,1)+SEQUENCE(10,1,0)

Generic Version: =start_date+SEQUENCE(number_of_days,1,0)

The above Excel formula in cell A2 will generate the dates from 01-Jan-2022 to 10-Jan-2022, i.e., ten days, in cell range A2:A11.

You may require to format A2:A11 to Date. How?

You can do that in Excel 365 by selecting A2:A11 and clicking Date (Short Date or Long Date) in the number format box on the Home tab > Number group.

What about a Time sequence?

Excel Formula # 2:

=TIME(0,0,0)+MOD(SEQUENCE(1*24,1,0)/24,1)

Generic Version: =start_time+MOD(SEQUENCE(number_of_days*24,1,0)/24,1)

The above formula in cell C2 will generate the time sequence from 00:00:00 hrs. to 23:00:00 hrs. in the range C2:C25. The time interval will be one hour.

Here also, you may require to format this range.

Here, instead of Long/Short Date, select Time in the format box on the Home tab Number group.

Combining the above two outputs won’t generate the sequence of DateTime in Excel? 

Please take a look at columns A, C, and E.

DateTime Sequence Formula in Excel

We have ten dates in column A and the time sequence is only for one day (24 hours).

We must repeat each date from 01-Jan-2022 to 10-Jan-2022 twenty-four times and repeat the time sequence ten times.

That’s not a big issue in an Excel spreadsheet, though.

Instead of combining, we can use a single formula in cell E2.

I have the below formula to generate the DateTime sequence in Excel 365.

Excel Formula # 3:

=DATE(2022,1,1)+SEQUENCE(10*24,1,0)/24

Generic Version: =start_date+SEQUENCE(number_of_days*24,1,0)/24

This time we should format the range E2:E241 to dd-mm-yyyy hh:mm:ss.

How to Format Date Value to DateTime in Excel?

  1. Select the range to format here E2:E241.
  2. Go to the Home tab Number group and click More Number Formats (inside the format box).
  3. Select Custom category and enter the above custom formatting under the Type field.

Extracting the Date and Time into Separate Columns from DateTime Sequence

Date:

Just wrap INT with the sequence part of the above formula # 3.

=DATE(2022,1,1)+INT(SEQUENCE(10*24,1,0)/24)

You may format the output to Short or Long Date.

Time:

To get the time parts separately, use formula # 2. But you should replace 1*24 with 10*24.

=TIME(0,0,0)+MOD(SEQUENCE(10*24,1,0)/24,1)

You may format the output to Time.

Time Sequence with 30 or 15 Minutes Interval in Excel

In all the above examples, we were using 60 minutes (1-hour) intervals.

For example, take the C2 formula, i.e., formula # 2.

In that Excel formula, replace 24 with 48 to get a time sequence with 30 minutes intervals.

=TIME(0,0,0)+MOD(SEQUENCE(1*48,1,0)/48,1)

To get a time sequence with 15 minutes intervals, replace 24 with 96.

=TIME(0,0,0)+MOD(SEQUENCE(1*96,1,0)/96,1)

Does this apply to our DateTime sequence formula # 3 in cell E2?

Yep! The same changes are applicable there also.

Excel 365 Resources

  • Sumif between Two Dates in Excel (How-To).
  • Date Wise Running Total Array Formula in Excel.
  • Array Formula to Combine Texts and Dates in Excel 365.
  • Copying Rows Containing Dates in a Column in Excel 365.
  • All Necessary Rules to Highlight Dates in Excel 365.
  • Count By Date, Month, Year, Date Range in Excel 365 (Array Formula).
  • Reverse Sequence in Excel 365 – Formula and Examples.

For work with dates in Excel, in the category «Date and time» is defined in the functions section. Let`s consider the most prevalent functions in this category.



How Excel Processes Time

The Excel program «perceives» the date and time as an ordinary number. The spreadsheet converts to such number, equating the day to unity. As a result, the time value represents a fraction of unity. For example, 12. 00 — is 0. 5.

The date value to the spreadsheet converts to a number which equal to the number of days from January 1, 1900 (so the developers decided) to the specified date. For example, when converting the date 13. 04. 1987, the number is 31880. That is, from 1. 01. 1900 passed 31. 880 days.

This principle underlies in the basis of the calculations of the time data. To find the number of days between two dates, it`s enough to take an earlier period from a later time one.



The example of DATE function

You need to describe of the date value with compiling it with individual elements of numbers.

There is the syntax: year; month, day.

All arguments are required. They can be specified by numbers or by reference to cells with the corresponding numeric data: for the year — from 1900 to 9999; for the month — from 1 to 12; for the day — from 1 to 31.

If you point a larger number for the «Day» argument (than the number of days in the pointed month), you receive the extra days, will be passed to the next month. For example, specifying 32 days for December, we will receive as a result on January 1.

The example of using the function:

example.

Let’s set more days for June:

days June.

Examples of using the cell references as arguments:

cell references as arguments.

The DATEDIF function in Excel

It returns the difference between two dates.

The arguments:

  • start date;
  • final date;
  • the code indicating to the units of counting (days, months, years, etc.).

The methods of measuring intervals between the given dates:

  • to display the result in days — «d»;
  • in months – «m»;
  • in years – «y»;
  • in months without years – «ym»;
  • in days without months and years – «md»;
  • in days without years – «yd».

In some versions of Excel, if you use the last two arguments («md», «yd»), the function may give an error. It is better to use to alternative formulas.

The examples of the operation the DATEDIF function:

DATEDIF.

In Excel 2007 version, this function is not in the directory, but it works. But you need to check the results are better, because there are flaws possible.

The YEAR function in Excel

It returns the year as an integer number (from 1900 to 9999), what corresponds to the specified date. There is only one argument must be entered in the structure of the function – is the date in a numerical format. The argument must be entered using the DATE function or represents to the result of evaluating other formulas.

The example of using the YEAR function:

YEAR.

The MONTH function in Excel: the example

It returns the month as an integer number (from 1 to 12) for a date is specified in a numeric format. The argument – is the date of the month that you want to show in a numerical format. The dates in the text format this function does not handle correctly.

The examples of using the MONTH function:

MONTH.

The examples of DAY, WEEKDAY and functions WEEKNUM in Excel

It returns the day as an integer number (from 1 to 31) for a date specified in a numeric format. The argument – it is the date of the day you want to find in a numerical format.

DAY.

For returning of the weekday ordinal of the specified date, you can apply the function WEEKDAY:

WEEKDAY.

By default, the function considers Sunday the 1-st day of the week.

To display of the ordinal number of the week for the pointed date, you should use the WEEKNUM function:

WEEKNUM.

The date of 24. 05. 2015 is 22 week in a year. The week starts on Sunday (by default).

week starts.

As the second argument the figure 2 is specified. Therefore, the formula considers that the week starts on Monday (the 2-d day of the week).

Download all examples functions for working with dates

For indicating of the current date, the function TODAY (no arguments) is used. To display the current time and date, the function NOW() is used.

Date and time in excel are treated a bit differently in excel than in other spreadsheets software. If you don’t know how Excel date and time work, you may face unnecessary errors.

So, in this article, we will learn everything about the date and time of Excel. We will learn, what are dates in excel, how to add time in excel, how to format date and time in excel, what are date and time functions in excel, how to do date and time calculations (adding, subtracting, multiplying etc. with dates and times).

What is Date and Time in Excel?

Many of you may already know that Excel dates and time are nothing but serial numbers. A date is a whole number and time is a fractional number. Dates in excel have different regional formatting. For example, in my system, it is mm/dd/YYYY (we will use this format throughout the article). You may be using the same date format or you could be using dd/mm/YYYY date format.

Date Formatting of Cell

There are multiple options available to format a date in Excel. Select a cell that may contain a date and press CTRL+1. This will open the Format Cells dialogue box. Here you can see two formatting options as Date and Time. In these categories, there are multiple date formattings available to suit your requirements.

Capture

Capture1Dates:

Dates in Excel are mare serial numbers starting from 1-Jan-1900. A day in excel is equal to 1. Hence 1-Jan-1900 is 1, 2-Jan-1900 is 2, and 1-Jan-2000 is 36526.

Fun Fact: 1900 was not a leap year but excel accepts 29-Feb-1900 as a valid date. It was a desperate glitch to compete Lotus 1-2-3 back in those days.

Shortcut to enter static today’s date in excel is CTRL+; (Semicolon).

To add or subtract a day from a date you just need to subtract or add that number of days to that date.

Time:
Excel by default follows the hh:mm format for time (0 to 23 format). The hours and minutes are separated by a colon without any spaces in between. You can change it to hh:mm AM/PM format. The AM/PM must have 1 space from the time value. To include seconds, you can add :ss to hh:mm (hh:mm:ss). Any other time format is invalid.

Time is always associated with a date. The date comes before the time value separated with a space from time. If you don’t mention a date before time, by default it takes the first date of excel (which is 1/1/1900). Time in excel is a fractional number. It is shown on the right side of the decimal.

Hours: 

Since 1 day is equal to 1 in excel and 1 day consists of 24 hours, 1 hour is equal to 1/24 in excel. What does that mean? It means that if you want to add or subtract 1 hour to time, you need to add or subtract 1/24. See the image below.

Capture3you can say that 1 hour is equal to 0.041666667 (1/24).

Calculate hours between time in Excel

Minutes:

From the explanation of the hour in excel, you must have guessed that 1 Minute in excel is equal to 1/(24×60) (or 1/1440 or 0.000694444).

If you want to add a minute to an excel time, add 1/(24×60). See the image below. Sometimes you get the need to Calculate Minutes Between Dates & Time In Excel, you can read it here.

Capture4Seconds:

Yes, a second in Excel is equal to 1/(24x60x60). To add or subtract seconds from a time, you just need to do the same things as we did in minutes and hours.

Date and Time in one cell

Dates and times are linked together. A date is always associated with a valid date and time is always associated with a valid excel date. Even if you are not able to see one of them.

If you only enter a time in a cell, the date of that cell will  1-Jan-1900, even if you are not able to see it. If you format that cell as a date-time format, you can see the associated date. Similarly, if you don’t mention time with the date, by default 12:00 AM is attached. See the image below.

Capture

In the image above, we have time only in B3 and date only in B4. When we format these cells as mm/dd/yy hh:mm, we get both, time and date in both cells.

So, while doing date and time calculations in excel, keep this in check.

No Negative Time

As I told you the date and time in excel starts from 1-Jan-1900 12:00 AM. Any time before this is not a valid date in excel. If you subtract a value from a date that leads to before 1-Jan-1900 12:00, even one second, excel will produce ###### error. I have talked about it here and in Convert Date and Time from GMT to CST. It happens when we try to subtract something that leads to before 1 Jan-1900 12:00. Try it yourself. Write 12:00 PM and subtract 13 hours from it. see what you get.

Calculations with Dates and Time in Excel

Adding Days to a date:

Adding days to a date in excel is easy. To add a day to date just add 1 to it. See the image below.

Capture
You should not add two dates to get the future date, as it will sum up the serial numbers of those days and you may get a date far in the future.

Subtracting Days from Date:

If you want to get a backdate from a date a few days before, then just subtract that number of days from the date and you will get backdate. For example, if I want to know what date was before 56 days since TODAY then I would write this formula in the cell.

This will return us the date of 56 before the current date.
Note: Remember that you can not have a date before 1/Jan/1900 in excel. If you get ###### error, this could be the reason.

Days between two dates:
To calculate days between two dates we just need to subtract the start date from the end date. I have already done an article on this topic. Go and check it out here. You can also use the Excel DAYS Function to calculate days between a start date and end date.

Adding Times:
There’s been a lot of queries on how to add time to excel as many people get confusing results when they do it. There are two types of addition in times. One is adding time to another time. In this case, both times are formatted as hh:mm time format. In this case, you can simply add these times.

The second case is when you don’t have additional time in time format. You just have numbers of hours, minutes and seconds to add. In that case, you need to convert those numbers to their time equivalents. Note these points to add hours, minutes and seconds to a date/time.

  • To add N hours to an X time use formula =X+(N/24) (As 1=24 hours)
  • To Add N minutes to X time use formula = X+(N/(24*60))
  • To Add N Second to X time use formula = X+(N/(24*60*60))

Subtracting Times

It’s the same as adding time, just make sure that you don’t end up with a negative time value when subtracting, because there is no such thing as a negative number in excel.

Note: When you add or subtract time in excel that exceeds 24 hours of difference, excel will roll to the next or previous date. For example, if you subtract 2 hours from 29-Jan-2019 1:00 AM then it will roll back to 28-Jan-2019 11:00 PM. If you subtract 2 hours from 1:00 AM (does not have the date mentioned), Excel will return ###### error. I have told the reason at the beginning of the article.

Adding Months to a Date:

You can’t just add multiples of 30 to add months to date as different months have a different number of days. You need to be careful while adding months to Date. To add months to a date in excel, we use EDATE function of excel. Here I have a separate article on adding months to a date in different scenarios.

Adding years to date:

Just like adding months to a date, it is not straightforward to add years to date. We need to use YEAR, MONTH, DAY function to add years to date. You can read about adding years to date here.

If you want to calculate years between dates then you can use this.

Excel Date and Time Handling Functions:

Since date and time are special in Excel, Excel provides special functions to handle them. Here I am mentioning a few of them.

  1. TODAY(): This function returns today’s date dynamically.
  2. DAY(): Returns Day of the month (returns number 1 to 31).
  3. DAYS(): Used to count the number of days between two dates.
  4. MONTH(): Used to get the month of the date (returns number 1 to 12).
  5. YEAR(): Returns year of the date.
  6. WEEKNUM(): Returns the weekly number of a date, in a year.
  7. WEEKDAY(): Returns the day number in a week (1 to 7) of the supplied date.
  8. WORKDAY():  Used to calculate working days.
  9. TIMEVALUE(): Used to extract Time value (serial number) from a text formatted date and time.
  10. DATEVALUE(): Used to extract date value (serial number) from a text formatted date and time.

These are some of the most useful data and time functions in excel. There are plenty more date and time functions. You can check them out here.

Date and Time Calculations

If I explain all of them here, this article will get too long. I have divided these time calculation techniques in excel into separate articles. Here I am mentioning them. You can click on them to read.

  • Calculate days, months and years
  • Calculate age from date of birth
  • Multiplying time values and numbers.
  • Get Month name from Date in Excel
  • Get day name from Date in Excel
  • How to get a quarter of the year from date
  • How to Add Business Days in Excel
  • Insert Date Time Stamp with VBA

So yeah guys, this is all about the date and time in excel you need to know about. I hope this article was useful to you. If you have any queries or suggestions, write them down in the comments section below.

Bottom line: With Valentine’s Day rapidly approaching I thought it would be good to explain how you can get a date with your Excel skills.  Just kidding! 🙂  This post and video explain how the date calendar system works in Excel.

Skill level: Beginner

Learn How Dates Work in Excel

Dates in Excel can be just as complicated as your date for Valentine’s Day.  We are going to stick with dates in Excel for this article because I’m not qualified to give any other type of dating advice. 🙂

Video Tutorial on How Dates Work in Excel

The following is a video from The Ultimate Lookup Formulas Course on how the date system works in Excel.

Watch the Video on YouTube

There are over 100 short videos just like the one above included in the Ultimate Lookup Formulas Course.

This course has been designed to help you master Excel’s most important functions and formulas in an easy step-by-step manner.

The Ultimate Lookup Formulas course is now part of our comprehensive Elevate Excel Training Program.

Click Here to Learn More About Elevate Excel

What is a Date in Excel?

I should first make it clear that I am referring to a date that is stored in a cell.

The dates in Excel are actually stored as numbers, and then formatted to display the date.  The default date format for US dates is “m/d/yyyy” (1/27/2016).

Excel Dates Are Stored as Serial Numbers and Formatted as Dates

The dates are referred to as serial numbers in Excel.  You will see this in some of the date functions like DAY(), MONTH(), YEAR(), etc.

Date Functions Have a Serial Number Argument for a Date Value

So then, what is a serial number?  Well let’s start from the beginning.

The date calendar in Excel starts on January 1st, 1900.  As far as Excel is concerned this day starts the beginning of time.

Each Day is a Whole Number

Each day is represented by one whole number in Excel.  Type a 1 in any cell and then format it as a date.  You will get 1/1/1900.  The first day of the calendar system.

Type a 2 in a cell and format it as a date.  You will get 1/2/1900, or January 2nd.  This means that one whole day is represented by one whole number is Excel.

Excels Date System Starts on January 1st 1900

You can also take a cell that contains a date and format it as a number.

For example, this post was published on 1/27/2016.  Put that number in a cell (the keyboard shortcut to enter today’s date is Ctrl+;), and then format it as a number or General.

You will see the number 42,396.  This is the number of days that have elapsed since 1/1/1900.

Keyboard Shortcut to Enter Todays Date Excel Ctrl Semicolon

Date Based Calculations

It is important to know that dates are stored as the number of days that have elapsed since the beginning of Excel’s calendar system (1/1/1900).

When you calculate the difference between two dates by subtraction, the result will be the number of days between the two dates.

Calculate the Difference Between Two Dates in Excel - Returns Number of Days

1/27/2016 – 1/1/2016 = 26 days

6/30/2016 – 1/1/2016 = 181 days

There are a lot of Date functions in Excel that can help with these calculations.  Last week we learned about the DAY function for month-to-date calculations with pivot tables.

Ust the DAY Function to Return Day of Month in the Pivot Table Source Data

We won’t go into all the date functions here, but understanding that the serial number represents one day will give you a good foundation for working with dates.

What About Dates with Times?

Do you ever work with dates that contain time values?

These dates are still stored as serial numbers in Excel.  When you convert the date with a time to the number format, you will see a decimal number.

This decimal is a fraction of the day.

The Time Value is Stored as a Fraction of the Serial Number Day

One hour in Excel is represented by the number: 1/24 = 0.04167

One minute in Excel is represented by the number: 1/(24*60) = 1/1440 = 0.000694

So 8:30 AM can be calculated as: (8 * (1/24)) + (30 * (1/1440)) = .354167

An easier way to calculate this is by typing 8:30 AM in a cell, then changing the format to Number.

So if you are running a half hour late and want to let your boss know, text him/her and say you will be there at 0.354167. 🙂

Checkout my article on 3 ways to group times in Excel for more date time based calculations.

Don’t Talk About Excel Dates with Your Date

Unless your Valentine shares a similar passion for Excel, I strongly recommend NOT sharing this information on your date.

I remember the first time I met my wife, and told her I worked in finance.  The first word out of her mouth was, “BORING!”.  Awe… it was love at first sight… LOL 🙂

But you should now be able to use Excel to determine how many days it has been since you last spoke to your date.  That’s the only dating advice I can give.

Please leave a comment below with any questions on Excel dates.  Thanks!

Whenever you enter a date in a cell, Excel automatically recognizes the format and converts the cell to a date cell.

So, Excel knows which part of the date you entered is the month, which is the year and which is the day.

This can be quite helpful in many ways. One particular benefit of this capability of Excel is that it lets you display the date in any format you want. It even lets you extract parts of the date that you need.

For example, you might find the day part of the date irrelevant and just need to display the month and year.

Since Excel already understands your date, you can easily extract just the month and year and display it in any format you like.

In this tutorial, we are going to see three ways in which you can convert date to month and year in Excel.

The Sample Data

Throughout this tutorial, we are going to be using the following set of dates. We will be converting these dates to month and year in Excel:

The sample data

When working with dates, first and foremost, it is important to recognize the original format your Excel dates are in. For example, in the US format, dates usually begin with the month and end with the year (mm/dd/yyyy).

In the UK and other countries, dates begin with the day and end with the year (dd/mm/yyyyy). In still other places like China, Iran, and Korea, the order is completely flipped (yyyy/mm/dd).

Depending on your computer’s date settings Excel will treat parts of your date differently. So when entering the date, make sure you check the format and enter the date in the correct order. You don’t want the date 2/10 to be treated as October, the 2nd instead of February, the 10th!

Convert Date to Month and Year using the MONTH and YEAR function

The MONTH and YEAR functions can help you extract just the month or year respectively from a date cell. In order for this method to work, the original date (on which you want to operate) must be a valid Excel date. If not, then both these functions will return a #VALUE error.

Let’s see how you can extract the month from our sample data:

  1. Click on a blank cell where you want the month to be displayed (B2)
  2. Type: =MONTH, followed by an opening bracket (.
  3. Click on the first cell containing the original date (A2).
  4. Add a closing bracket )
  5. Press the Return key.Getting the month number from the date using the MONTH function
  6. This should display the month of the year corresponding to the original date. Copy this to the rest of the cells in the column by dragging down the fill handle or double-clicking on it.

You will see column B populated by the month of the year for all the dates of column A.

MONTH function result

Now let’s see how you can extract the year from the same dataset:

  1. Click on a blank cell where you want the year to be displayed (C2)
  2. Type: =YEAR, followed by an opening bracket (.
  3. Click on the first cell containing the original date (A2).
  4. Add a closing bracket )
  5. Press the Return key.Getting the year number from the date using the YEAR function
  6. This should display the year corresponding to the original date. Copy this to the rest of the cells in the column by dragging down the fill handle or double-clicking on it.

You will see column C populated by the year corresponding to all the dates of column A.

Year function result

Now let’s see how you can combine the results of the two to display both month and year in a nice format.

Let us say you want to display both month and year as “2-2018” for the date “02/10/2018”, and want to follow this pattern for all the dates.

  1. Click on a blank cell where you want the new date format to be displayed (D2)
  2. Type the formula: =B2 & “-“ & C2. Alternatively, you can type: =MONTH(A2) & “-” & YEAR(A2).
  3. Press the Return key.Combine and create the date using ampersand
  4. This should display the original date in our required format. Copy this to the rest of the cells in the column by dragging down the fill handle or double-clicking on it.

Now all your cells in column D2 have the new format:

Month and year separated by dashonth and year separated by dash

Alternatively, if you want to display your month and year as 2/2018 instead, you only need to replace the “-“ in-between with a “/”. In this way, you can display the month and year in any format that you like.

Month and year separated by forward slash

Finally, if you want to just keep the converted values and want to remove the original dates and any intermediate columns that you created you need to first convert the formula results into constant values.

For this, copy the cells of column D and paste them as values in the same column (Right-click and select Paste Options->Values from the Popup menu). Now you can go ahead and delete columns A to C. You will be left with only the converted values that have the month and year.

Copy and paste dates as values

Although this is quite an easy and intuitive way to convert dates to months and years, it is a less popular method. This is because this method does not provide a lot of flexibility compared to the other two methods we will show next.

Also read: How to Calculate the Number of Months Between Two Dates in Excel?

Convert Date to Month and Year using the TEXT Function

The TEXT function in Excel converts any numeric value (like date, time, and currency) into text with a specified format.

The syntax of the TEXT function is:

= TEXT (value, format_code)

Here,

  • value is the numeric value or reference to the cell that you want to convert
  • format_code is the format you want to convert the cell into

In the above example, the TEXT function applies the format_code that you specified on the value and returns a text string with that format. For example, if you have a date “2/10/2018” in cell A2, then =TEXT(A2, “mm/yyyy”) will return “02/2018”

There are a number of format codes that you can use. We have enlisted below the basic building blocks for the format codes:

Format Codes for Year:

You can use the following two basic format codes to represent year values:

  • yy – two-digit representation of year (e.g. 20 or 12)
  •  yyyy – four-digit representation of year (e.g. 2020 or 2012)

So, if you apply =TEXT(A2, yy) in our example dataset, it will return “18”.

If you apply =TEXT(A2, yyyy), then it will return “2018”.

Format Codes for Month of the Year:

You can use the following four basic format codes to represent month values:

  • m – one or two-digit representation of the month (eg; 8 or 12)
  • mm – two-digit representation of the month (eg; 08 or 12)
  • mmm – month abbreviated in three letters (eg: Aug or Dec)
  • mmmm – month expressed with the full name (eg: August or December)

So, if you apply =TEXT(A2, m) in our example dataset, it will return “2”.

  • If you apply =TEXT(A2, mm), then it will return “02”.
  • If you apply =TEXT(A2, mmm), then it will return “Feb”.
  • If you apply =TEXT(A2, mmmm), then it will return “February”.

Let us see how we can apply the TEXT function to our sample dataset to convert all the dates to different formats.

We will first see how to convert the dates in column A to the format shown in column B in the image below:

Converting dates using the TEXT formula

Below are the steps to change the date format and only get month and year using the TEXT function:

  1. Click on a blank cell where you want the new date format to be displayed (B2)
  2. Type the formula:
    =TEXT(A2,”m/yy”)
  3. Press the Return key.
  4. This should display the original date in our required format. Copy this to the rest of the cells in the column by dragging down the fill handle or double-clicking on it.TEXT formula
  5. Copy this column’s formula results by pressing CTRL+C or Cmd+C (if you’re on a Mac).
  6. Right-click on the column and form the popup menu that appears, press Paste Values from the Paste Options.
  7. This will store the formula results as permanent values in the same column. Now you can go ahead and remove column A if you want to.Copy and paste dates as values from TEXT function

The format code that you put in the formula (at step 2) will vary according to the format you want your month and year to appear in. Here are the format codes along with the type of result you will get when applied to cell A2:

Function Result
=TEXT(A2, “mm/yy”) 02/18
=TEXT(A2, “mm-yy”) 02-18
=TEXT(A2, “mm-yyyy”) 02-2018
=TEXT(A2, “mmm, yyyy”) Feb, 2018
=TEXT(A2, “mmmm, yyyy”) February, 2018

Dates in different formats

So you see, you can use the TEXT function to convert your dates to any format of your choice. All you need to do is change the format code according to your requirement.

Note: Using this formula, your date gets converted to a text format. If you want to convert it back to a date format, you need to use the Format Cells feature.

Also read: How to Convert Text to Date in Excel?

Convert Date to Month and Year using Number Formatting

Excel’s Format Cell feature is a versatile one that lets you perform different types of formatting through a single dialog box.

Here’s how you can convert the dates in our sample dataset to different formats.

  1. Select all the cells containing the dates that you want to convert (A2:A6).
  2. Right-click on your selection and select Format Cells from the popup menu that appears. Alternatively, you can select the dialog box launcher in the Number group under the Home tab.Click on the dialog box launcher
  3. This will open the Format Cells dialog box. Click on the Number tab
  4. Under Category on the left side of the box, select the Date option.
  5. This will display a number of formatting options for date on the right side.
  6. Select the format that you want. For example, if you want to display the first date in the format “Feb-18”, then select the matching format option.Choosing the date number format
  7. If you don’t find an option for the format you want to use, then you can use the Custom option from the Category list on the left. This lets you convert the cell to a custom format.
  8. Look if your format is available among the date format codes under Type. If not, you can type in your format code in the input box just below Type. So, if you want to display the first month in the format “2/18”, then type “m/yy”.Creating custom date format
  9. Click OK to close the Format Cells dialog box.

All your selected cells should now be formatted to your required format.

Date formatted as required

This method differs from the previous one (using the TEXT function) in four ways:

  • With this method, you can perform the operation directly on the original cells.
  • You can get your conversion done in one go. So you don’t need to have a separate cell to enter the formula, then paste by value and then delete the original cells (as you would need to if using the TEXT function).
  • This method changes just the format of the original date, the underlying date, however, remains the same. So if you want to later recover the original date value (along with the day), you can easily access it. With the TEXT function method, however, the original date value is lost because the conversion changes the entire value of the date.
  • The results you get from using this method are of type Date, rather than Text, so you can perform date operations on them directly without having to convert them.

These were three ways in which you can convert date to month and year in Excel. Using these you can convert your date to any format you need.

We hope you found our methods useful and that you will apply it to your own Excel data.

Other Excel tutorials you may like:

  • How to Convert Decimal to Fraction in Excel
  • How to Add Days to a Date in Excel
  • How to Sort by Date in Excel (Single Column & Multiple Columns)
  • How to Convert Serial Numbers to Date in Excel
  • How to Convert Date to Day of Week in Excel
  • How to Convert Month Number to Month Name in Excel
  • How to Convert Days to Years in Excel (Simple Formulas)
  • Convert Military Time to Standard Time in Excel (Formulas)
  • Convert YYYYMMDD to MM/DD/YYYY in Excel
Skip to content

All Excel’s Date Functions Explained + Time Functions Too! [+5500 words]

All Excel’s Date and
Time Functions Explained!

Written by co-founder Kasper Langmann, Microsoft Office Specialist.

This is the complete guide to date and time in Excel.

It’s a whopping +5500 words (!), so be sure to bookmark it.

The first part of the guide shows you exactly how to deal with dates in Excel.

I will show you how to perform calculations involving dates. We’re also going to look at some of Excel’s (awesome) built-in functions. These allow you to extract just what you need from data that includes dates.

In the second part of the guide, I’ll show you how to work with time data in a spreadsheet.

This is going to be a lot of fun. Grab a cup of coffee, and let’s start rolling!

Kasper Langmann, Co-founder of Spreadsheeto
  • 7: Date formatting

    • What is date formatting?
    • How to use other date formats (from the ‘Format Cells’ dialog box)
    • How to use custom date format
    • Turn text into dates with the DATEVALUE function
    • How to auto populate date in Excel when a cell is updated
    • How to insert a date picker in Excel

Get your FREE exercise file

Before you start:

Throughout this guide, you need a data set to practice.

I’ve included one for you (for free).

Download it right below!

Introduction to
calculations with dates

When analyzing and manipulating date information in Excel, you have several formatting options.

In other words, you can display your data in many ways.

Most of the time, Excel will know that you are entering a date when you key in the data like the following:

  • 1/1/2017
  • January 1, 2017
  • 1-Jan

The clearest sign that Excel has stored your data in a cell as a date is that it should be right-aligned in the cell.

Kasper Langmann, Co-founder of Spreadsheeto

Below are a few examples of the various formats that Excel displays dates in.

But the key is that they are all aligned to the right of the cell.

Data formatted as data versus text

Contrast column A with column B (where the cells are formatted as text). They show the same information.

But, the alignment to the left side of the cell indicates that they are not formatted as a date. As you will soon see, this presents problems when performing calculations with dates.

Kasper Langmann, Co-founder of Spreadsheeto

One important note about how Excel stores dates:

To use dates in calculations, Microsoft Excel stores dates as serial numbers.

These are the sequential number of the day in relation to the starting date of January 1, 1900.

Short data format and serial number

So, think of January 1, 1900, as serial number 1.

January 1, 2016, would be serial number 42370 as it’s 42,370 days after January 1, 1900.

For this reason, dates need to be in a date format rather than text format. If stored in text format, their serial number will not be stored in Excel. This is a no-go as you need these serial numbers when you want to perform calculations involving dates.

Kasper Langmann, Co-founder of Spreadsheeto

How to add time to dates in Excel

Now you know the fundamentals of date formatting versus date data formatted as text. Let’s look at some calculations you can do with dates.

First, why don’t we look at how to add days to a date?

Kasper Langmann, Co-founder of Spreadsheeto

How to add days to a date

Adding days to a date is very simple, straightforward, and intuitive.

All you need to do is add the number of days as a single number to the date or cell reference containing the date.

The following figure illustrates just how simple it is to add 1 day or 90 days to a date.

Example of adding days

How to add months to a date

If you need to add a month or several months to your date, the process is a bit more complicated.

For this calculation, you will need to call upon the built-in Excel function, EDATE. The syntax for EDATE is so simple, that you will pick it up in no time at all.

Kasper Langmann, Co-founder of Spreadsheeto

Here’s its syntax:

=EDATE(start_date, months)

The function requires 2 arguments: ‘start_date’ and ‘months’.

The first, ‘start_date’, is simply the date we are adding months to.

The second, ‘months’, is the number of months we would like to add to the date.

Look at the figure below to see just how easy it is to calculate a new date by adding 6 months and 9 months to the start date.

Adding months to a date

How to add years to a date

So, what about calculating the addition of years to your original date?

For this, you need to use a few more functions. But, as noted before, this is super intuitive so don’t let the length of these formulas fool you.

Kasper Langmann, Co-founder of Spreadsheeto

The first function we need to focus on is DATE.

The syntax for DATE is also incredibly simple and intuitive:

=DATE(year, month, day)

But, for our purposes, we can use the YEAR, MONTH, and DAY functions along with DATE.

These functions extract the correct data from our original date. This ensures appropriate use of our final DATE formula.

For example, applying MONTH to a cell reference of our original date will extract the month data. The same is true for YEAR and DAY.

So, we will place these functions in the appropriate argument within the DATE function. And if we want to add 1 year to the date, we simply place a ‘+1’ after the YEAR function in the ‘year’ argument of the DATE function.

Kasper Langmann, Co-founder of Spreadsheeto

That was a lot, so let’s look at the following figure to see it in action.

The function DATE in action

Notice row 18 and column C of the worksheet.

The ‘year’ argument of the ‘DATE’ function is substituted by the function ‘YEAR(A18)+1’.

This tells the DATE function that we want the year only from the date data in A18 (or 2017) – and that we want to add ‘1’ to it (or 2018).

How to subtract dates

Adding time to a date is super useful.

But what if you had a report where you needed to calculate the difference between dates?

This is where we turn our attention to subtracting dates…

Kasper Langmann, Co-founder of Spreadsheeto

Find the difference between two dates

To find the difference between two dates, we want to turn our attention to the DATEDIF function.

The most important thing you need to know about DATEDIF is that it is a hidden function. What that means is that it will not be found in the visible list of Excel functions on the formula tab.

Kasper Langmann, Co-founder of Spreadsheeto

This requires you to type the formula in its entirety.

There will be no tooltip hint as you begin to type the function.

Let’s look at the syntax:

=DATEDIF(start_date, end_date, unit)

There are three arguments for the DATEDIF function:

  • start_date: This is the initial date of the period among the two you are calculating the difference between.
  • end_date: This is the latest date of the two.
  • unit: This is the unit in which you want the function to return the difference by. More on units right below…

The ‘unit’ argument gives you a choice of several formats to return your results from DATEDIF.

  • y – The number of complete years between dates.
  • m – The number of complete months between dates.
  • d – The number of days between dates.
  • md – The number of days ignoring months and years.
  • yd – The number of days ignoring years.
  • ym – The number of months ignoring days and years.

So, let’s look at a few examples using DATEDIF in various forms.

Kasper Langmann, Co-founder of Spreadsheeto
Function DATEDIF

In our example, you can use literal dates if they are enclosed in double quotes.

You can also use the serial number format as shown in rows 4 and 5.

Now note the difference in the returned value between row 2 and 3. The ‘start_date’ and the ‘end_date’ are unchanged. But, our results are different. The first formula returns the total number of days between the dates.

Kasper Langmann, Co-founder of Spreadsheeto

But in the second example, we use ‘md’ for the unit argument. ‘md’ is the difference between the dates in days – ignoring the months and years. That is 15 minus 1, or 14 days.

You can also calculate the difference between two dates in cells.

To do this, place the cell reference of your dates in the ‘start_date’ and ‘end_date’ arguments.

Difference between two dates in cells

One (last) important thing to note about using DATEDIF:

The ‘end_date’ argument must always be later than the ‘start_date’ or you will get the ‘#NUM!’ error.

Use today’s date in Excel

Now let’s turn our attention to some tricks and shortcuts involving the current date.

Often, you need to work with the current (today’s) date.

There are some nifty tricks that allow you to do this without typing in the entire date manually.

Let’s look at them!

Use date that updates itself with the TODAY function

One of the simplest ways to input today’s date into a cell is to use the TODAY function.

Do this by typing ‘=TODAY()’ into a cell.

This places the current date into the cell dynamically. So, that cell would have tomorrow’s date in it if you reopen the file tomorrow.

You can also nest the TODAY function within the DAY or MONTH function. This return only the current day or current month in a cell. Refer to the following figure to see the TODAY function in action.

Kasper Langmann, Co-founder of Spreadsheeto
TODAY function

Insert static current date in Excel using shortcuts

You can also insert the current date using keyboard shortcuts.

For the current date, press the following key combination:

Ctrl + ;

To insert both the date and the time, press the previous keyboard shortcut. Then press the following combination:

Ctrl + Shift + ;

These shortcuts enter static dates and times. This opposed to the dynamic date that the TODAY function returns.

Subtract a date from the current date

You can use the current date in a calculation like subtracting.

You replace the ‘start_date’ argument in the DATEDIF formula.

Subtract a date with DATEDIF

Above image shows how to substitute the TODAY function for a literal date value or cell reference for the ‘start_date’ OR the ‘end_date’.

Remember the rule that the ‘end_date’ must be later than the ‘start_date’ still applies.

Using the TODAY function in a calculation is useful when you need to track a time period dynamically. Say you need to calculate some sort of countdown to a deadline. Using the TODAY function in your calculation is the perfect way to do this.

Kasper Langmann, Co-founder of Spreadsheeto

You can also use the keyboard shortcut to insert the current date if you need to insert the static date. This is a quicker and more efficient way to insert today’s date.

Retrieving numbers from dates
with Date functions

There are often situations where you need to retrieve numbers from dates.

But, you might not have the need for an entire date.

Let’s say you have a report. Here you want to separate the different elements of the date for filtering by a single element of the date – like the month or year.

Here’s how to go about doing that 🙂

Use the DAY function to find the day of a date

To isolate only the day of the full date, we use the DAY function.

There is a single argument for the DAY function:

=DAY(serial_number)

You probably know by now that ‘serial_number’ is the date.

This argument can be the actual serial number form of the date or the literal date in double quotes. It can also be a cell reference like in the following example.

DAY function

Look at above picture again. Notice that regardless of the format of your original date, the DAY function returns the value ‘14’.

Use the MONTH function to find the month of a date

If you need to isolate the number value for the month of your original date, you can use the MONTH function.

It works the same way the DAY function works:

=MONTH(serial_num)

MONTH function

Use the YEAR function to find the year of a date

Now we move onto the function that retrieves the number value for the year part of the date.

The syntax for the ‘YEAR’ function is like the DAY and MONTH functions syntactically.

=YEAR(serial_num)

You already know how to retrieve the day and month number values. It’s the exact same concept when using the ‘YEAR’ function.

YEAR function

Use the WEEKDAY function to find the day of the week

You can also retrieve the number value for the day of the week from a date.

The WEEKDAY function returns the number that corresponds to the day of the week. For instance, 1 for Sunday, 2 for Monday, 3 for Tuesday, and so on.

Kasper Langmann, Co-founder of Spreadsheeto

Here’s its syntax:

=WEEKDAY(serial_num, [return_type])

The syntax for WEEKDAY requires the ‘serial_number’ argument.

It also allows for an optional argument: ‘return_type’.

This allows you to choose a different start and end date for your week.

That means that the returned value will align with that chosen sequence.

Below you can see the list of different ‘return_type’ values that Excel allows.

WEEKDAY function

In the following examples, note the value differences returned by the formula based on the ‘return_type’ argument.

Value differences returned by formula based on ‘return_type’ argument

The different selections for the ‘return_type’ in the formulas return very different weekday values.

These depend on the first day of the week that corresponds to those ‘return_type’ values.

Use the WEEKNUM function
to find out the week number

Another interesting built-in function is the WEEKNUM function.

WEEKNUM retrieves the number value for the week of the year that the original date falls within (1 – 52).

So, if the original date is between January 1 and January 7, the WEEKNUM value would be ‘1’.

If the date is between December 25 and December 31, WEEKNUM would return the value ‘52’.

=WEEKNUM(serial_number, [return_type])

The ‘return_type’ argument corresponds to different days you can choose as the start day. This changes the week number based on what day of the week that the ‘return_type’ sets as the first day of the year.

Kasper Langmann, Co-founder of Spreadsheeto
WEEKNUM function

Our date falls on a Monday.

The result of the WEEKNUM formula will be different if the ‘return_type’ argument is ‘1’ (Sunday) versus ‘12’ (Tuesday).

This can be useful since the calendar year begins on different days of the week. This comes in handy if want to calculate the week number based on the first full week of the year.

Kasper Langmann, Co-founder of Spreadsheeto
WEEKNUM example

This can be a very useful function.

Consider a situation in which you needed a weekly countdown. Simply calculate the difference between dates using the WEEKNUM function.

Use the WORKDAY function to calculate the number of working days between two dates

Another useful function is the WORKDAY function.

This function returns a day that is some number of workdays into the future or before some date. A “workday” is days excluding weekends and any holidays that are specified.

The function requires two arguments and has an optional third.

=WORKDAY(start_date, days, [holidays])

  • start_date this required argument is the date from when you want to count the number of workdays
  • days this required argument is the number of days from the start date you want a count of. Using a negative number will give you the date that many workdays before your start date.
  • holidays this argument is optional. This allows you to add holiday dates in the formula for the WORKDAY function to skip along with weekends.

This is a bit more complex than the functions we have been discussing. Let’s look at a few examples to help the concept of the WORKDAY function sink in.

Kasper Langmann, Co-founder of Spreadsheeto
Function WORKDAY

First, note that we have listed 3 holiday dates in cells A8, A9, and A10. We will be using these in our examples for the ‘holiday’ argument to exclude along with weekends.

On row 2, we want to know the date that is 90 workdays from Monday, November 14, 2016.

Excluding the weekends and holidays (A8:A10), this will be Tuesday, March 21, 2017 according to the WORKDAY function.

On row 3, we can instantly see the effect of weekends and holidays on the outcome of our formula. We want the date that is 2 workdays from Wednesday, November 23, 2017.

Because of the holiday on Thursday, November 24 – and the weekend days Saturday and Sunday – the result is Monday, November 28, 2016.

This example illustrates how powerful the WORKDAY function can be. It calculates something very simple. Yet, if done manually, this is a very cumbersome process.

Kasper Langmann, Co-founder of Spreadsheeto

The third example in the figure illustrates how to use WORKDAY to find a date before the start date.

We want to know the date that is 20 workdays before Monday, January 17, 2017.

So, our DAY argument needs to be a negative value (-20).

Again, note the result considers weekend days as well as a couple of holidays.

How to auto fill dates

In this section, we are going to cover how to work with sequences of dates. This time by using the autofill capability of Microsoft Excel.

You can use Autofill in 2 ways.

The first is to double-click the fill handle. The fill handle is a small square that appears in the lower right corner of a highlighted cell.

The second option is to simply drag the handle to the desired cell. Note the fill handle for the highlighted cell in the following figure.

Auto fill handle

The fill handle also offers some more options.

Try to right-click and drag outside the selection a bit.

Auto fill menu

We will focus on the selections that fill elements of the date like days, weekdays, months, and years.

Insert dates that increase by one day

To insert dates that increase by one day in a column, you can simply grab the fill handle.

Then drag it down as many rows as you need dates for.

One thing to take note of is that as you do this, Excel shows the incremented date as you drag the range.

So, you can see just what date you are at as you expand the range.

Expand range

Once you release the fill handle, your range is now filled with dates.

These dates increment in one-day intervals.

Range expanded

Insert dates that increase by weekdays

But what if you wanted to increment a wide range of dates by weekdays only?

This is easily done by selecting ‘Fill Weekdays’ from the ‘Autofill Options’ that appears once you fill the dates down.

Fill weekdays

Once you select ‘Fill Weekdays’, Excel automatically excludes any weekend dates from the range.

Weekdays added

Insert dates that increase by months and years

You can also use the ‘Autofill Options’ to increase months and years.

Select the fill option you need once you fill the dates down to the last cell of your range.

Autofill examples

Insert dates that increase by several days

I’m sure you can think of other custom intervals (dates) you might like to fill down your column (or row, for that matter).

Microsoft Excel allows for a little of that also.

So, what if you wanted to increment every other day? Or what about every 3 months?

These other intervals are available using auto fill. Drag down the dates by using the fill handle. Then right click and hold on the fill handle while moving the cursor slightly outside the range. Now release until you see the options menu.

Kasper Langmann, Co-founder of Spreadsheeto
Series

Click on ‘Series…’. The Series dialog box will now open.

This gives you several options for customizing the intervals of your dates.

Series dialog box

For our example of every other day, you can select a Step value of ‘2’.

Leave everything else as it is.

Every other day

Date formatting:
Make a date easy to interpret

In the beginning of this tutorial, I told you about the differences between text format and date format.

Now, we’re going to take a deeper dive into formatting of dates. We can represent date data in different date formats. These are easily adjusted according to our preferences and needs.

Kasper Langmann, Co-founder of Spreadsheeto

Also, remember our point earlier, that Excel stores date data as serial number.

So, no matter what date format you choose, Excel still recognizes it as a serial number.

What is date formatting?

Date formatting offers you choices on how you want to represent the date data in your worksheets.

Let’s look at our original example at the beginning of this tutorial.

We can see in the Number group of the Home tab that our data cells are all formatted as Date.

Date formatting

If you take the same data and place it into another column, something interesting happens.

In the cells that are formatted as ‘General’, you’d see the dates serial numbers.

Formatted as date and general

If you run into this in your own spreadsheets, you must know how to fix this…

It’s quite simple, you just need to know how to reformat those cells into the Date format that you need.

For this example, let’s reformat to ‘Short date’.

Highlight the cell containing the serial number. Click on the drop-down arrow to see all the available formats in the Number group of the Home tab.

Short date

Select ‘Short Date’ from the dropdown and now the serial number will be converted from ‘General’ format to a date format that you recognize.

Short date applied

How to use other date formats
from the ‘Format Cells’ dialog box

You’ve now seen how to change date data formatted as ‘General’ to the ‘Short Date’ format.

Now we look at some other date formats that Excel also offers…

You already know how to change to a date format from the ribbon but you can also use the ‘Format Cells’ dialog box.

The first step is to find the cell that contains the serial number you want to reformat.

Then, right-click on the cell.

Select ‘Format Cells’ from the menu that appears.

Format cells dialog box

From the Format Cells dialog box, select ‘Date’ in the Category box.

This reveals the different standard date format types available in Excel.

You find these formats in the Type box on the right side of the Format Cells dialog box. As you change Type selections, you can view a sample of the actual value in the cell you have selected in the Sample box.

Kasper Langmann, Co-founder of Spreadsheeto
Format cells as date

Decide on the ‘Type’ you want.

Then click ‘OK’ and the serial number now changes to the date format type you selected.

Converted date

How to use custom date format

Even with all the date types Excel offers, you can still format your date data with your own custom format.

It is pretty simple to do…

Follow the same steps as we did with the previous example.

But, instead of choosing ‘Date’ in the Category box in the Format Cells dialog box, select ‘Custom’.

Format cells as custom

Take a second look at the picture above.

Here the Format Cells dialog box shows the current format of the cell in the Type and Sample boxes.

Now you can select from the various default types available. You can also edit those types in the Type box or type in one that is completely custom.

Kasper Langmann, Co-founder of Spreadsheeto

Let’s clear out the Type box…

Clear type box

And then type “mm-dd-yyyy”  into that box:

mm-dd-yyyy

Again, note that as we do this, the Sample box shows us our exact data as it will look under our new custom format. Click ‘OK’ and you are done creating your own custom date format.

Kasper Langmann, Co-founder of Spreadsheeto

Turn text into dates with the DATEVALUE function

Another method for converting dates in text format is to use a function called DATEVALUE.

This function converts text string dates to their appropriate serial numbers.

These serial numbers are, as you know by now, the way Excel recognizes dates. You can format this output according to the methods I’ve shown you in the prior sections.

Kasper Langmann, Co-founder of Spreadsheeto

The DATEVALUE syntax is simple:

=DATEVALUE(date_text)

So, let’s look at a few examples of cells containing dates that are in text string form.

Let’s use the DATEVALUE function in the column next to these cells.

Here it’s easy to see if the cells return the serial numbers we expect.

DATEVALUE

If your text date is before the year 1900, the DATEVALUE function will return the ‘#VALUE!’ error.

That’s because Excel recognizes dates as serial numbers beginning at January 1, 1900.

If your text date doesn’t contain a year, the DATEVALUE function defaults to the current year from your system clock.

How to auto populate date when a cell is updated

What if you wanted to make sure each time a cell’s data got updated, you knew when it was updated?

You could input the date and time manually in the cell next to it.

But what if you wanted to automate that process?

That way you’ll never forget to do it. Also, you would mitigate the chances for a data entry error.

There are several ways to approach this. One of the best ways is to use VBA to create a worksheet change event. It is a macro that automatically runs when a cell’s value changes.

Kasper Langmann, Co-founder of Spreadsheeto

A quick recommendation:

Excelribbon.tips.net has written an awesome guide that demonstrates a worksheet change event. Make sure to check it out!

How to insert a date picker in Excel

Another cool thing you can do in Excel with dates is to create a date picker. This allows users to choose a date from a preset dropdown calendar. That way they don’t have to input the date by hand.

This is actually a pretty complex proposition in Excel. But if you want to see a date picker and a bit about how one can be created using VBA. Contextures has an amazing guide to do it right here.

Calculations with Time

Maybe you need to quantify elapsed time for tasks or projects?

Or perhaps you need to insert a time rather than a date in your data?

There are many parallels between the techniques of working with dates and time.

How to add time in Excel

Let’s look at a scenario where you have documented the total time it took for two different tasks in Excel.

Now you want to add those together to get your total time worked.

This is as simple as clicking on the cell below the task times and pressing Alt + = to autosum the times.

SUM time

Now let’s look at a scenario where you have the times worked for a full workweek that you need to add together for a total.

If we autosum once again, we immediately notice a problem.

AUTOSUM time problem

We know by simple inspection that these workday time values add up to more than 12 hours and 52 minutes.

Excel can display times in a variety of ways. For instance, hours and minutes, 12-hour format, and 24-hour format, and several others.

Kasper Langmann, Co-founder of Spreadsheeto

What we need to do in our current situation is to right click on the cell where our auto sum formula is.

Then select Format Cells like we did with dates.

hours minutes minutes

Then select ‘Custom’ from the Category box and clear the Type box.

Then in the Type box, type ”[h]:mm”.

Click ‘OK’ and you should have the correct total of hours for the week now.

Time correct displayed

How to find the difference between two times

Finding the difference between times is not quite as simple as adding times together.

Let’s look at a situation where we have a start time and an end time and we want to calculate the total elapsed time.

Finding time difference

In cell B4, type the formula ‘=(B3-B2)*24’.

This subtracts the end time from the start time and then multiplies both by 24.

The multiplication by 24 is required since Excel recognizes times as a fraction of a full 24-hour day.

Formula =(B3-B2)*24

Our result is a numerical value and we choose to set it to two decimal places to show fractions of a full hour.

Numerical time difference

If you want to see the elapsed time in the actual hours and minutes, here’s what to do.

Remove the ‘*24’ and format using the custom format we created in the previous example adding times ([h]:mm).

Find current time in Excel

The NOW function allows you to insert the current time based on your computer’s system clock.

NOW returns the current date and time whereas TODAY returns the current date only.

But we can use NOW and format our cell so that it only shows the time but not the date.

NOW function

Insert static current time with shortcuts

You’ve already seen the keyboard shortcut for entering in the static current date as well as entering the static current time.

Since we are discussing time data, I’ll show you how to use a keyboard shortcut to enter the static current time.

All you must do is press the following keyboard combination:

Ctrl + Shift + ;

Again, this contrasts with using the NOW function because it is static rather than dynamic.

This keyboard shortcut inserts the exact time you pressed the keyboard shortcut. It will remain that time unless you manually change it.

Retrieve seconds, minutes and hours

Let’s look at retrieving parts of time data.

This is very much the same as when you retrieved the month, day, and year, from dates. We are going to retrieve the seconds, minutes, and hours with some built-in functions available in Excel.

If you want to retrieve the seconds from a time value in Excel, you use the built-in SECOND function.

There is a single required argument for this function: ‘serial_number’.

=SECOND(serial_number)

Let’s look at a few simple examples to see this function in action:

SECOND function

For times that don’t display the seconds, the SECOND function still retrieves the seconds from the serial number of the date.

If you need to retrieve the minutes from your time data, you want to use the MINUTE function. Like with SECOND function (and others), there is only the required ‘serial_number’ argument.

=MINUTE(serial_num)

Now we will take the same time data we used for the SECOND function and use the MINUTE function.

MINUTE function

The last thing we will look at is the HOUR function. Nothing new on the syntax.

=HOUR(serial_number)

One thing to note about the HOUR function is that it returns a value for the hour based on 24 hours.

So, if you want your HOUR function to return the hour in an AM/PM fashion, subtract 12 from your function if it is a time later than 12 PM.

HOUR function

Formatting time: What is it?

Just like with dates, there are several different format types for time data.

In fact, our examples so far have demonstrated a few of these different formats.

You may want to display times in 12-hour format or 24 hours. You might want your 12-hour format times to show AM and PM, or you may not.

Kasper Langmann, Co-founder of Spreadsheeto
Default time

You find the default time format types by right-clicking a cell.

Then select Format Cells.

Note in the figure above how many variations you can choose from. You can always create your own custom format by selecting ‘Custom’ from the Category list.

How to use and change time formatting

Now we have reviewed how you select different time formats.

Let’s look at a few examples of the different types.

We will look at 3 different selections from those available in the types for time formats.

The first thing we need to do to change format is to right click on the range of dates we want to reformat. Then select Format Cells.

Format cells

Once the Format Cells dialog opens, select ‘Time’ from the Category box. Then in the Type box select ‘*1:30:55 PM’.

Format cells as time

The asterisk in ‘*1:30:55 PM’ indicates that this format changes to the Region settings on your computer.

Any changes to the Windows time format settings will reflect in Excel. But only for the times formatted with a format preceded by an asterisk.

So, we format column B times as ‘*1:30:55 PM’ and then two other formats in columns C and D for the sake of contrast. Look at the different format variations in the following figure.

Kasper Langmann, Co-founder of Spreadsheeto
Examples of different times

Turn text into time with the TIMEVALUE function

The DATEVALUE function converts dates in text string form to date formatting.

Like DATEVALUE, the TIMEVALUE function converts text string time data to actual time format.

See the syntax here:

=TIMEVALUE(text_time)

The ‘text_time’ argument is required. It is simply the text string date that you need to convert to time format.

One thing to recall is that Excel recognizes time as a fraction of 24 hours. For instance, 12 pm would be interpreted by Excel as .5 since it is the halfway point of the 24-hour day.

Kasper Langmann, Co-founder of Spreadsheeto

So, when you use the TIMEVALUE function, you won’t get a time.

Rather, it returns a decimal number value that is a fraction of the entire day.

TIMEVALUE function

If you multiply the TIMEVALUE result by 24, you get a more accurate interpretation of the time (albeit still in decimal format).

TIMEVALUE in 24 hours

But if you reformat the TIMEVALUE result to a time format, you are good to go.

You will have changed a text string time to a true time format that Excel will now recognize as time instead of text.

Wrapping up

There it is, the most comprehensive guide to date and time in Excel.

It’s taken us tons of hours and resources to publish. Feel free to share it along with anyone who needs to brush up their dates and times 😊

If you enjoyed this tutorial, I’m sure you’ll love this…

Kasper Langmann2020-05-11T13:30:38+00:00

Page load link

Date Range in Excel Formula

We need to perform different operations like addition or subtraction on date values with Excel. By setting date ranges in Excel, we can perform calculations on these dates. For setting date ranges in Excel, we can first format the cells that have a start and end date as ‘Date’ and then use the operators: ‘+’ or ‘-‘to determine the end date or range duration.

For example, suppose we have two dates in cells A2 and B2. To create a date range, we may use the following formula with the TEXT function:

=TEXT(A2,”mm/dd”)&” – “&TEXT(B2,”mm/dd”)

Date Range in Excel

Table of contents
  • Date Range in Excel Formula
    • Examples of Date Range in Excel
      • Example #1 – Basic Date Ranges
      • Example #2 – Creating Date Sequence
      • Example #3
      • Example #4
    • Things to Remember
    • Recommended Articles

Examples of Date Range in Excel

You can download this Date Range Excel Template here – Date Range Excel Template

Example #1 – Basic Date Ranges

Let us see how adding a number to a date can create a date range.

Suppose we have a start date in cell A2.

Date Range Example 1

If we add a number, say 5, to it, we can build a date range.

Date Range Example 1-1

Date Range Example 1-2

When we select cell A3 and type “=B2 + 1.”

Date Range Example 1-3

Then, we need to copy cell B2 and paste it into cell B3; the relative cell referenceCell reference in excel is referring the other cells to a cell to use its values or properties. For instance, if we have data in cell A2 and want to use that in cell A1, use =A2 in cell A1, and this will copy the A2 value in A1.read more would change as follows:

Date Range Example 1-5

So we can see that multiple date ranges can be built this way.

Example #2 – Creating Date Sequence

With Excel, we can easily create several sequences. Now we know that dates are some numbers in Excel. So we can use the same method to generate date ranges. So to create date ranges that have the same range or gap, but the dates change as we go down, we can follow the below steps:

  • We must first type a start date and end date in a minimum of two rows.

Example 2

  • Then, select the ranges and drag them down below the row where we require the dates ranges.

Example 2-1

Date Range Example 2-2

So we can see that using the date ranges in the first two rows as a template, Excel automatically creates date ranges for the subsequent rows.

Example #3

Now, suppose we have two dates in two cells, and we wish to display them concatenated as a date range in a single cell. For doing this, we can use a formula based on the ‘TEXT’ function can be used. The general syntax for this formula is as follows:

= TEXT(date1,”format”) & ” – ” & TEXT(date2,”format”)

Case 1:

This function receives two date values as numeric and concatenates these two dates in the form of a date range according to a custom date format (“mmm d” in this case):

Date Range =TEXT(A2,”mmm d”) & “-” & TEXT(B2,”mmm d”)

Date Range Example 3

So we can see in the above screenshot that we have applied the formula in cell C2. The TEXT function receives the dates stored in cells A2 and B2. The ampersand ‘&’ operator is used to concatenate the two dates as a date range in a custom format, specified as “mmm d” in this case, in a single cell, and the two dates are joined with a hyphen ‘-‘ in the resultant date range which is determined in cell C2.

Case 2:

In this example, we wish to combine the two dates as a date range in a single cell with a different format, say “d mmm yy.” So the formula for a date range, in this case, would be as follows:

Date Range =TEXT(A3,”d mmm yy”) & “-” & TEXT(B3,”d mmm yy”)

Date Range Example 3-1

So we can see in the above screenshot that the TEXT function receives the dates stored in cells A3 and B3, and the ampersand ‘&’ operator is used to concatenate the two dates as a date range in a custom format, specified as “d mmm yy” in this case, in a single cell. Then, finally, the two dates are joined with a hyphen ‘-‘in the resultant date range determined in cell C3.

Example #4

Now let us see what happens if the start date or end date is missing. For example, suppose the end date is missing as follows:

Example 4

The formula based on the TEXT function that we have used above would not work correctly if the end date is missing. As the hyphen in the formula would anyhow be appended to the start date, i.e., along with the start date, we would also see a hyphen displayed in the date range. In contrast, we would only wish to see the start date as the date range if the end date is missing.

So, in this case, we can have the formula by wrapping the concatenation and the second TEXT function inside an IF clause as follows:

Date Range =TEXT(A2,”mmm d”) & IF(B2<> “”, “-” & TEXT(B2,”mmm d”), “”)

Example 4-1

So we can see that the above formula creates a full date range using both the dates when both are present. However, it displays only the start date in the specified format if the end date is missing. It is done with the help of an IF clause.

Now in case both the dates are missing, we could use a nested IF statement in excelIn Excel, nested if function means using another logical or conditional function with the if function to test multiple conditions. For example, if there are two conditions to be tested, we can use the logical functions AND or OR depending on the situation, or we can use the other conditional functions to test even more ifs inside a single if.read more, (i.e., one IF inside another IF statement) as follows:

Date Range =IF(A4<>””,TEXT(A4,”mmm d”) & IF(B4<> “”, “-” & TEXT(B4,”mmm d”), “”),””)

Date Range Example 4-2

So we can see that the above formula returns an empty string if the start date is missing.

If both the dates are missing, an empty string is also returned.

Date Range Example 4-3

Things to Remember

  • We can even create a list of sequential dates using the ‘Fill Handle’ command. We can select the cell having a start date and then drag it to the range of cells where we wish to fill. Next, click on the “Home” tab -> “Editing” ->”Fill Series” and then choose a date unit we want to use.
  • If we wish to calculate the duration or number of days between two dates, we can subtract the two dates using the ‘-‘operator, and we will get the desired result.

Example (Subtract)

Note: The format of cells: A2 and B2 is ‘Date,’ whereas that of cell C2 is ‘General’ as it calculates the number of days.

Recommended Articles

This article has been a guide to Date Range in Excel. Here, we discuss formulas to create date ranges in Excel in different ways and a downloadable Excel template. You may learn more about Excel from the following articles: –

  • DATE Excel Function
  • EDATE Excel Function
  • Subtract Date In Excel
  • Compare Dates in Excel

Date Time LeadDates and times are two of the most common data types people work with in Excel, but they are also possibly the most frustrating to work with, especially if you are new to Excel and still learning. This is because Excel uses a serial number to represent the date instead of a proper month, day, or year, nevermind hours, minutes, or seconds. It’s made more complicated by the fact that dates are also days of the week, like Monday or Friday, even though Excel doesn’t explicitly store that information in the cells. Here is the definitive guide to working with dates and times in Excel…

How Excel Stores Dates

The source of most of the confusion around dates and times in Excel comes from the way that the program stores the information. You’d expect it to remember the month, the day, and the year for dates, but that’s not how it works…

Excel stores dates as a serial number that represents the number of days that have taken place since the beginning of the year 1900. This means that January 1, 1900 is really just a 1. January 2, 1900 is 2. By the time we get all the way to the present decade, the numbers have gotten pretty big… September 10, 2013 is stored as 41527.

Importantly, any date before January 1, 1900 is not recognized as a date in Excel. There are no “negative” date serial numbers on the number line.

It seems confusing, but it makes it a lot easier to add, subtract, and count days. A week from September 10, 2013 (September 17, 2013), is just 41527 + 7 days, or 41534.

How Excel Stores Times

Excel stores times using the exact same serial numbering format as with dates. Days start at midnight (12:00am or 0:00 hours). Since each hour is 1/24 of a day, it is represented as that decimal value: 0.041666…

That means that 9:00am (09:00 hours) on September 10, 2013 will be stored as 41527.375.

When a time is specified without a date, Excel stores it as if it occurred on January 0, 1900. In other words, 3:00pm (15:00 hours) is stored as 0.625. This can make doing math for time-only values (that have no date) challenging, since subtracting 6 hours (6:00)  from 3:00am (03:00 hours) will become negative and count as an error: 0.125 – 0.25 = -0.125, which is displayed as #########.

Minutes and seconds in Excel work the same way as hours…

A minute is 1/60 of an hour, which is 1/24 of a day, or 1/1440 of a day in total, which calculates to 0.00069444…

A second is 1/60 of an minute, which is 1/60 of an hour, which is 1/24 of a day, or 1/86400 of a day in total, which calculates to 0.00001157407…

Working with Dates and Times

DATE() and TIME()

Serial numbers aren’t all that intuitive to use. Fortunately, Excel has a set of functions to make it easier to find and use dates and times, starting with DATE and TIME. The syntax is as follows:

=DATE(yearmonthday)
=TIME(hoursminutesseconds)

For both functions, specify the year, month, and day, or hours, minutes, and seconds as numbers. For example, September 10, 2013 can be entered as:

=DATE(2013,9,10)

It will be stored as 41527, which means that it is technically storing 12:00am on September 10, 2013.

For times, 6:00pm (18:00 hours) can be entered as:

=TIME(18,0,0)

It will be stored as 0.75, which means that it is technically storing 6:00pm on January 0, 1900.

If we want to represent a specific time and date, we can add the two functions together. For example, 6:00pm (18:00 hours) on September 10, 2013 can be entered as:

=DATE(2013,9,10)+TIME(18,0,0)

It will be calculate as 41527.75, which means Excel is storing exactly the date we want…

Additional Date and Time Setting Functions

Excel has a few additional functions to make declaring dates easier.

TODAY()

The TODAY function always returns the current date’s serial number. The TODAY function is just entered as:

=TODAY()

This article was written at 6:30pm (18:30 hours) on September 24, 2013, and the TODAY function calculated to 41541.  That means that it is technically storing 12:00am on September 24, 2013.

NOW()

A similar function called NOW always returns the current date and time’s serial number. The NOW function is just entered as:

=NOW()

Again,  at 6:30pm (18:30 hours) on September 24, 2013, the function calculated to 41541.77081333… NOW stores the exact time and date, down to the second.

EDATE() and EOMONTH()

The EDATE function gives the date the specified number of months away from the input date. The EOMONTH function gives the date of the last day of the month. It can do so for the current month or a number of months in the future or the past. The syntax for each is as follows:

=EDATE(start_date, months)
=EOMONTH(start_date, months)

The start_date can be any date-formatted cell reference or date serial number.

The months field can be any number, though only the integer value will be used (e.g. it treats 2.8 as 2).

The EDATE and EOMONTH functions strip the time value from the date. For example, For example, if cell A1 stores September 10, 2013, we can get the value 2 months ahead as follows:

=EDATE(A1,2)

Returns 12:00am (0:00 hours) on November 10, 2013, or 41588. This function works even though the months have different numbers of days (September and November have 30, October has 31).

=EOMONTH(A1,2)

Returns 12:00am (0:00 hours) on November 30, 2013, or 41588. Again, this function works even though the months have different numbers of days.

WORKDAY()

Occasionally, it may be useful to count ahead based on work-days (Monday-Friday) instead of all 7 days of the week… For that, Excel has provided WORKDAY. The syntax for WORKDAY is as follows:

=WORKDAY(start_date, days, [holidays])

The start_date is as above.

The days input is the number of workdays ahead (or behind) of the present day you would like to move.

The [holidays] input is optional, but lets you disqualify specific days (like Thanksgiving or Christmas, for example), which might otherwise fall during the work week. These are date serial numbers provided in an array bounded by brackets: { }. To specify multiple holidays, the dates must be held in cells – it is not possible to put multiple DATE functions in an array.

For example, let’s find the date 6 work days before 6:00pm (18:00 hours) on September 10, 2013 (stored in cell A1). Monday, September 2nd is Labor Day, so let’s include that as a holiday:

=WORKDAY(A1,-6,DATE(2013,9,2))

Returns 12:00am (0:00 hours) on August 30, 2013, or 41516. (Note that the function strips the time portion of the date.)

WORKDAY.INTL() (Excel 2010 and newer)

For newer versions of Excel (2010 and later), there is another version of WORKDAY called WORKDAY.INTL. WORKDAY.INTL works just like WORKDAY, but it adds the ability to customize the definition of the “weekend”. The syntax for WORKDAY.INTL is as follows:

=WORKDAY.INTL(start_date, days, [weekend], [holidays])

The start_date, days, and [holidays] inputs work just like the normal WORKDAY function.

The [weekend] input has the following options:

WorkDay.Intl Weekend

Retrieving Dates in Excel

DAY(), MONTH(), and YEAR()

Now we know how define dates, but we still need to be able to work with them. Serial numbers don’t make it easy to extract months, years, and days, nevermind hours, minutes, and seconds. That’s why Excel has specific functions for pulling out each of these values. For working with the calendar, there is DAY, MONTH, and YEAR. The syntax is simple:

=DAY(serial_number)
=MONTH(serial_number)
=YEAR(serial_number)

The serial_number in each can be any date-formatted cell reference. For example, if cell A1 stores September 10, 2013, we can use each of the formulas in turn:

=DAY(A1)

Returns 10 as a numeric value.

=MONTH(A1)

Returns as a numeric value.

=YEAR(A1)

Returns 2013 as a numeric value.

We could have also given the direct serial number for September 10, 2013:

=DAY(41527)

Returns 10 as a numeric value.

Retrieving Times in Excel

HOUR(), MINUTE(), and SECOND()

For times, the process is very similar. Excel has function to retrieve the hours, minutes, and seconds from a time stamp, conveniently named HOUR, MINUTE, and SECOND. The syntax is identical:

=HOUR(serial_number)
=MINUTE(serial_number)
=SECOND(serial_number)

The serial_number in each can be any time/date-formatted cell reference. For example, if A1 stores 6:15:30pm (18:15 hours, 30 seconds) on September 10, 2013, we can use each of the formulas in turn:

=HOUR(A1)

Returns 18 as a numeric value.

=MINUTE(A1)

Returns 15 as a numeric value.

=SECOND(A1)

Returns 30 as a numeric value.

We could have also given the direct serial number for  6:15:30pm (18:15 hours, 30 seconds) on September 10, 2013:

=SECOND(41527.7607638889)

Returns 30 as a numeric value.

Additional Date Retrieving Functions

WEEKDAY() and WEEKNUM()

Dates don’t just have month and year information. They also encode indirect information… September 10, 2013 happens to also be a Tuesday. Excel has a few of functions to work with the week aspect of dates: WEEKDAY and WEEKNUM. The syntax is as follows:

=WEEKDAY(serial_number, [return_type])
=WEEKNUM(serial_number, [return_type])

The serial_number in each can be any date-formatted cell reference. Since [return_type] is optional, each function assumes that each week starts on Sunday. If cell A1 stores September 10, 2013 (a Tuesday), we can use each of the formulas in turn:

=WEEKDAY(A1)

Returns 3, since Tuesday is the 3rd day of a week that starts on Sunday.

=WEEKNUM(A1)

Returns 37, since September 10, 2013 is in the 37th week of 2013, when you start counting weeks from Sunday.

The [return_type] allows you to specify a different default week arrangement. You could let the week start on Monday and run until Sunday, or Saturday until Friday, for example. Excel is annoying, however, and makes the entry different for WEEKDAY and WEEKNUM. The full list of options for WEEKDAY is as follows:

Week Return Type

Options 2 and 11 are functionally the same – the first is just there for backwards compatibility with earlier versions of Excel.

The full list of options for WEEKNUM is as follows:

WeekNum Return Type

Counting and Tracking Dates

Dates can be added and subtracted like normal numbers because they’re stored as serial numbers. That lets you count the days between two different dates. Sometimes, though, you need to count by a different metric.

NETWORKDAYS()

Above, we learned about WORKDAY, which lets you move back and forth a set number of workdays, ignoring weekends and holidays. But what if you need to measure the number of workdays between two dates? For that, Excel provides NETWORKDAYS. The formula syntax is as follows:

=NETWORKDAYS(start_date, end_date, [holidays])

The start_date and end_date can be any date-formatted cell reference.

The [holidays] input is optional, but lets you disqualify specific days (like Thanksgiving or Christmas, for example), which might otherwise fall during the work week. These are date serial numbers provided in an array bounded by brackets: { }. To specify multiple holidays, the dates must be held in cells – it is not possible to put multiple DATE functions in an array.

For example, if A1 contains 6:00pm (18:00 hours) on September 10, 2013 and B1 contains 9:00am (9:00 hours) on December 2, 2013, we can use NETWORKDAYS to find the number of workdays between the two dates.

Let’s exclude Columbus Day (October 14, 2013), Veterans Day (November 11, 2013), and Thanksgiving Day (November 28, 2013) as holidays. To do so, we have to store those dates in other cells. Let’s put them in C1, C2, and C3:

=DATE(2013,10,14)
=DATE(2013,11,11)
=DATE(2013,11,28)

Now, we can combine them in the function:

=NETWORKDAYS(A1,B1,C1:C3)

The function returns 57 as a numeric value.

NETWORKDAYS.INTL() (Excel 2010 and newer)

For newer versions of Excel (2010 and later), there is another version of NETWORKDAYS called NETWORKDAYS.INTLNETWORKDAYS.INTL works just like NETWORKDAYS, but it adds the ability to customize the definition of the “weekend”. The syntax for NETWORKDAYS.INTL is as follows:

=NETWORKDAYS.INTL(start_date, end_date, [weekend], [holidays])

The start_dateend_date, and [holidays] inputs work just like the normal WORKDAY function.

The [weekend] input has the following options:

NETWORKDAYS.Intl Weekend

YEARFRAC()

Sometimes it’s useful to measure how much time has passed in years, but subtracting the YEAR function will only round down to the nearest full year. YEARFRAC takes two dates and provides the portion of the year between them. The syntax is as follows:

=YEARFRAC(start_date, end_date, [basis])

The start_date and end_date can be any date-formatted cell reference.

The [basis] input is optional, but lets you specify the “rules” for measuring the difference. Most of the time, you’ll want to use option 1, but here is the full list:

YearFrac BasisFor example, if A1 contains September 10, 2013 and B1 contains December 2, 2013, we can use YEARFRAC to find the decimal portion of a year between the two dates:

=YEARFRAC(A1,B1,1)

Returns 0.227397260273973.

DATEDIF() (Undocumented Function)

The YEARFRAC function gives you the difference between dates as a fraction of a year, but sometimes you need more control. There is a powerful hidden function in Excel called DATEDIF that can do much more. It can tell you the number of years, months, or days between two dates. It can also track based on only partial inputs, ignoring years or months when calculating days. The syntax for DATEDIF is as follows:

=DATEDIF(start_date, end_date, unit)

The start_date and end_date can be any date-formatted cell reference.

The unit input asks you to specify a string that represents the type of output you want. This is slightly cumbersome, since you must wrap the input in quotes (” “).

For example, if A1 contains September 10, 2012 and B1 contains December 2, 2013, we can use DATEDIF to find the number of full years between the two dates:

=DATEDIF(A1,B1,"Y")

Returns 1 as a numeric value.

Using the same start_date and end_date inputs, here are the output possibilities for DATEDIF using different unit parameters:

DateDif Unit

Every time, the unit must be put in quotes (e.g. “Y” or “MD”).

Converting Dates and Times from Text

DATEVALUE() and TIMEVALUE()

All of the above functions work perfectly with date-formatted serial numbers in Excel. Unfortunately, dates and times are often imported into worksheets as text. Most of the assorted functions like MONTH and HOUR are reasonably intelligent about converting on the fly. Occasionally it’s useful to build a date value through concatenation. The two functions Excel provides for this purpose are DATEVALUE and TIMEVALUE. The syntax for each is as follows:

=DATEVALUE(date_text)
=TIMEVALUE(time_text)

The date_text and time_text accept any text string that looks like a date or time.

This is how DATEVALUE responds to various date_text inputs:

DateValue Text Examples

This is how TIMEVALUE responds to various time_text inputs:

TimeValue Text Examples

Converting Dates and Times to Text

TEXT()

Getting data converted to dates and times is great, but you may also need to get it back out. Sometimes, you need a special format. Other times, you need to look for a date in a text string, and have to match using string tools like FIND and SEARCH. There is one master function for converting dates and times to text strings in Excel, called TEXT. The syntax for TEXT is as follows:

=TEXT(value, format_text)

The value can be any date or time-formatted cell reference.

The format_text input has a large number of options, summarized here:

Text Format_Text Inputs

The outputs can be combined with simple formatting characters to produce standard date formats. Using the date 5:07:03am (05:07 hours, 3 seconds) on September 10, 2013, here are examples of possible outputs:

Text Output Examples

A Common Problem

One issue people frequently run into is that Excel occasionally misinterprets text fields as dates. An example is here:

Common Error

Be careful when entering dates, especially if you are importing from other data sources, to make sure that your “Jan-13” is being stored as January 1, 2013 and not January 13, 2013!

Get the latest Excel tips and tricks by joining the newsletter!

Andrew Roberts ThumbnailAndrew Roberts has been solving business problems with Microsoft Excel for over a decade. Excel Tactics is dedicated to helping you master it.

Join the newsletter to stay on top of the latest articles. Sign up and you’ll get a free guide with 10 time-saving keyboard shortcuts!

Other posts in this series…

Like this post? Please share to your friends:
  • From analysis services excel
  • From an older english word
  • From adjectives from the following word
  • From access to excel 2010
  • From a word with these letters