Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel for the web Excel 2021 Excel 2021 for Mac Excel 2019 Excel 2019 for Mac Excel 2016 Excel 2016 for Mac Excel 2013 Excel 2010 Excel 2007 Excel for Mac 2011 Excel Starter 2010 More…Less
To get detailed information about a function, click its name in the first column.
Note: Version markers indicate the version of Excel a function was introduced. These functions aren’t available in earlier versions. For example, a version marker of 2013 indicates that this function is available in Excel 2013 and all later versions.
Function |
Description |
DATE function |
Returns the serial number of a particular date |
DATEDIF function |
Calculates the number of days, months, or years between two dates. This function is useful in formulas where you need to calculate an age. |
DATEVALUE function |
Converts a date in the form of text to a serial number |
DAY function |
Converts a serial number to a day of the month |
DAYS function |
Returns the number of days between two dates |
DAYS360 function |
Calculates the number of days between two dates based on a 360-day year |
EDATE function |
Returns the serial number of the date that is the indicated number of months before or after the start date |
EOMONTH function |
Returns the serial number of the last day of the month before or after a specified number of months |
HOUR function |
Converts a serial number to an hour |
ISOWEEKNUM function |
Returns the number of the ISO week number of the year for a given date |
MINUTE function |
Converts a serial number to a minute |
MONTH function |
Converts a serial number to a month |
NETWORKDAYS function |
Returns the number of whole workdays between two dates |
NETWORKDAYS.INTL function |
Returns the number of whole workdays between two dates using parameters to indicate which and how many days are weekend days |
NOW function |
Returns the serial number of the current date and time |
SECOND function |
Converts a serial number to a second |
TIME function |
Returns the serial number of a particular time |
TIMEVALUE function |
Converts a time in the form of text to a serial number |
TODAY function |
Returns the serial number of today’s date |
WEEKDAY function |
Converts a serial number to a day of the week |
WEEKNUM function |
Converts a serial number to a number representing where the week falls numerically with a year |
WORKDAY function |
Returns the serial number of the date before or after a specified number of workdays |
WORKDAY.INTL function |
Returns the serial number of the date before or after a specified number of workdays using parameters to indicate which and how many days are weekend days |
YEAR function |
Converts a serial number to a year |
YEARFRAC function |
Returns the year fraction representing the number of whole days between start_date and end_date |
Important: The calculated results of formulas and some Excel worksheet functions may differ slightly between a Windows PC using x86 or x86-64 architecture and a Windows RT PC using ARM architecture. Learn more about the differences.
Need more help?
Содержание
- Date and time functions (reference)
- Time duration with days
- Related functions
- Summary
- Generic formula
- Explanation
- More than 31 days
- How to calculate time in Excel — time difference, adding / subtracting times
- How to calculate time difference in Excel (elapsed time)
- Formula 1. Subtract one time from the other
- Formula 2. Calculating time difference with the TEXT function
- Formula 3. Count hours, minutes or seconds between two times
- Formula 4. Calculate difference in one time unit ignoring others
- Formula 5. Calculate elapsed time from a start time to now
- Formula 5. Display time difference as «XX days, XX hours, XX minutes and XX seconds»
- How to calculate and display negative times in Excel
- Method 1. Change Excel Date System to 1904 date system
- Method 2. Calculate negative time in Excel with formulas
- Adding and subtracting time in Excel
- How to add or subtract hours to time in Excel
- How to add / subtract minutes to time in Excel
- How to add / subtract seconds to a given time
- How to sum time in Excel
- How to sum over 24 hours in Excel
- Date & Time Formula Wizard — quick way to calculate times in Excel
Date and time functions (reference)
To get detailed information about a function, click its name in the first column.
Note: Version markers indicate the version of Excel a function was introduced. These functions aren’t available in earlier versions. For example, a version marker of 2013 indicates that this function is available in Excel 2013 and all later versions.
Returns the serial number of a particular date
Calculates the number of days, months, or years between two dates. This function is useful in formulas where you need to calculate an age.
Converts a date in the form of text to a serial number
Converts a serial number to a day of the month
DAYS function
Returns the number of days between two dates
Calculates the number of days between two dates based on a 360-day year
Returns the serial number of the date that is the indicated number of months before or after the start date
Returns the serial number of the last day of the month before or after a specified number of months
Converts a serial number to an hour
ISOWEEKNUM function
Returns the number of the ISO week number of the year for a given date
Converts a serial number to a minute
Converts a serial number to a month
Returns the number of whole workdays between two dates
NETWORKDAYS.INTL function
Returns the number of whole workdays between two dates using parameters to indicate which and how many days are weekend days
Returns the serial number of the current date and time
Converts a serial number to a second
Returns the serial number of a particular time
Converts a time in the form of text to a serial number
Returns the serial number of today’s date
Converts a serial number to a day of the week
Converts a serial number to a number representing where the week falls numerically with a year
Returns the serial number of the date before or after a specified number of workdays
WORKDAY.INTL function
Returns the serial number of the date before or after a specified number of workdays using parameters to indicate which and how many days are weekend days
Converts a serial number to a year
Returns the year fraction representing the number of whole days between start_date and end_date
Important: The calculated results of formulas and some Excel worksheet functions may differ slightly between a Windows PC using x86 or x86-64 architecture and a Windows RT PC using ARM architecture. Learn more about the differences.
Источник
Time duration with days
Summary
To enter a time duration like 2 days 6 hours and 30 minutes into Excel, you can enter days separately as a decimal value, then add the time. In the example shown, the formula in cell F5, copied down, is:
Generic formula
Explanation
In the example shown, the goal is to enter a valid time based on days, hours, and minutes, then display the result as total hours.
The key is to understand that time in Excel is just a number. 1 day = 24 hours, and 1 hour = 0.0412 (1/24). That means 12 hours = 0.5, 6 hours = 0.25, and so on. Because time is just a number, you can add time to days and display the result using a custom number format, or with your own formula, as explained below.
In the example shown, the formula in cell F5 is:
On the right side of the formula, the TIME function is used to assemble a valid time from its component parts (hours, minutes, seconds). Hours come from column C, minutes from column D, and seconds are hardcoded as zero. TIME returns 0.5, since 12 hours equals one half day:
With the number 1 in C5, we can simplify the formula to:
which returns 1.5 as a final result. To display this result as total hours, a custom number format is used:
The square brackets tell Excel to display hours over 24, since by default Excel will reset to zero at each 24 hour interval (like a clock). The result is a time like «36:00», since 1.5 is a day and a half, or 36 hours.
The formula in G5 simply points back to F5:
The custom number format used to display a result like «1d 12h 0m» is:
More than 31 days
Using «d» to display days in a custom number format works fine up to 31 days. However, after 31 days, Excel will reset days to zero. This does not affect hours, which will continue to display properly with the number format [h].
Unfortunately, a custom number format like [d] is not supported. However, in this example, since days, hours, and minutes are already broken out separately, you can write your own formula to display days, minutes, and hours like this:
This is an example of concatenation. We are simply embedding all three numeric values into single text string, joined together with the ampersand (&) operator.
If you want to display an existing time value as a text string, you can use a formula like this:
where A1 contains time. The INT function simply returns the integer portion of the number (days). The TEXT function is used to format hours and minutes.
Источник
How to calculate time in Excel — time difference, adding / subtracting times
by Svetlana Cheusheva, updated on January 19, 2023
This tutorial focuses on various ways to calculate times in Excel. You will find a few useful formulas to add and subtract times, calculate time difference, or elapsed time, and more.
In the last week’s article, we had a close look at the specificities of Excel time format and capabilities of basic time functions. Today, we are going to dive deeper into Excel time calculations and you will learn a few more formulas to efficiently manipulate times in your worksheets.
How to calculate time difference in Excel (elapsed time)
To begin with, let’s see how you can quickly calculate elapsed time in Excel, i.e. find the difference between a beginning time and an ending time. And as is often the case, there is more than one formula to perform time calculations. Which one to choose depends on your dataset and exactly what result you are trying to achieve. So, let’s run through all methods, one at a time.
Add and subtract time in Excel with a special tool
No muss, no fuss, only ready-made formulas for you
Easily find difference between two dates in Excel
Get the result as a ready-made formula in years, months, weeks, or days
Calculate age in Excel on the fly
And get a custom-tailored formula
Formula 1. Subtract one time from the other
As you probably know, times in Excel are usual decimal numbers formatted to look like times. And because they are numbers, you can add and subtract times just as any other numerical values.
The simplest and most obvious Excel formula to calculate time difference is this:
Depending on you data structure, the actual time difference formula may take various shapes, for example:
Formula | Explanation |
=A2-B2 | Calculates the difference between the time values in cells A2 and B2. |
=TIMEVALUE(«8:30 PM») — TIMEVALUE(«6:40 AM») | Calculates the difference between the specified times. |
=TIME(HOUR(A2), MINUTE(A2), SECOND(A2)) — TIME(HOUR(B2), MINUTE(B2), SECOND(B2)) | Calculates the time difference between values in cells A2 and B2 ignoring the date difference, when the cells contain both the date and time values. |
Remembering that in the internal Excel system, times are represented by fractional parts of decimal numbers, you are likely to get the results similar to this:
The decimals in column D are perfectly true but not very meaningful. To make them more informative, you can apply custom time formatting with one of the following codes:
Time code | Explanation |
h | Elapsed hours, display as 4. |
h:mm | Elapsed hours and minutes, display as 4:10. |
h:mm:ss | Elapsed hours, minutes and seconds, display as 4:10:20. |
To apply the custom time format, click Ctrl + 1 to open the Format Cells dialog, select Custom from the Category list and type the time codes in the Type box. Please see Creating a custom time format in Excel for the detailed steps.
And now, let’s see how our time difference formula and time codes work in real worksheets. With Start times residing in column A and End times in column B, you can copy the following formula in columns C though E:
The elapsed time is displayed differently depending on the time format applied to the column:
Note. If the elapsed time is displayed as hash marks (#####), then either a cell with the formula is not wide enough to fit the time or the result of your time calculations is a negative value.
Formula 2. Calculating time difference with the TEXT function
Another simple technique to calculate the duration between two times in Excel is using the TEXT function:
- Calculate hours between two times: =TEXT(B2-A2, «h»)
- Return hours and minutes between 2 times: =TEXT(B2-A2, «h:mm»)
- Return hours, minutes and seconds between 2 times: =TEXT(B2-A2, «h:mm:ss»)
- The value returned by the TEXT function is always text. Please notice the left alignment of text values in columns C:E in the screenshot above. In certain scenarios, this might be a significant limitation because you won’t be able to use the returned «text times» in other calculations.
- If the result is a negative number, the TEXT formula returns the #VALUE! error.
Formula 3. Count hours, minutes or seconds between two times
To get the time difference in a single time unit (hours ,minutes or seconds), you can perform the following calculations.
Calculate hours between two times:
To present the difference between two times as a decimal number, use this formula:
Supposing that your start time is in A2 and end time in B2, you can use a simple equation B2-A2 to calculate the difference between two times, and then multiply it by 24, which is the number of hours in one day:
To get the number of complete hours, use the INT function to round the result down to the nearest integer:
Total minutes between two times:
To calculate the minutes between two times, multiply the time difference by 1440, which is the number of minutes in one day (24 hours * 60 minutes = 1440).
As demonstrated in the following screenshot, the formula can return both positive and negative values, the latter occur when the end time is less than the start time, like in row 5:
Total seconds between times:
To get the total seconds between two times, you multiply the time difference by 86400, which is the number of seconds in one day (24 hours * 60 minutes * 60 seconds = 86400).
In our example, the formula is as follows:
Note. For the results to display correctly, the General format should be applied to the cells with your time difference formula.
Formula 4. Calculate difference in one time unit ignoring others
To find the difference between 2 times in a certain time unit, ignoring the others, use one of the following functions.
- Difference in hours, ignoring minutes and seconds:
=HOUR(B2-A2)
Difference in minutes, ignoring hours and seconds:
=MINUTE(B2-A2)
Difference in seconds, ignoring hours and minutes:
When using Excel’s HOUR, MINUTE and SECOND functions, please remember that the result cannot exceed 24 for hours and 60 for minutes and seconds.
Note. If the end time is less than the start time (i.e. the result of the formula is a negative number), the #NUM! error is returned.
Formula 5. Calculate elapsed time from a start time to now
In order to calculate how much time has elapsed since the start time to now, you simply use the NOW function to return today’s date and the current time, and then subtract the start date and time from it.
Supposing that the beginning date and time is in call A2, the formula below returns the following results, provided you’ve applied an appropriate time format to column B, h:mm in this example:
In case the elapsed time exceeds 24 hours, use one of these time formats, for example d «days» h:mm:ss like in the following screenshot:
If your starting points contain only time values without dates, you need to use the TIME function to calculate the elapsed time correctly. For example, the following formula returns the time elapsed since the time value in cell A2 up to now:
=TIME(HOUR(NOW()), MINUTE(NOW()), SECOND(NOW())) — A2
Note. The elapsed time is not updated in real-time, it refreshes only when the workbook is reopened or recalculated. To force the formula to update, press either Shift + F9 to recalculate the active spreadsheet or hit F9 to recalculate all open workbooks.
Formula 5. Display time difference as «XX days, XX hours, XX minutes and XX seconds»
This is probably the most user-friendly formula to calculate time difference in Excel. You use the HOUR, MINUTE and SECOND functions to return corresponding time units and the INT function to compute the difference in days. And then, you concatenate all these functions in a single formula along with the text labels:
=INT(B2-A2) & » days, » & HOUR(B2-A2) & » hours, » & MINUTE(B2-A2) & » minutes and » & SECOND(B2-A2) & » seconds»
To instruct your Excel time difference formula to hide zero values, embed four IF functions into it:
=IF(INT(B2-A2)>0, INT(B2-A2) & » days, «,»») & IF(HOUR(B2-A2)>0, HOUR(B2-A2) & » hours, «,»») & IF(MINUTE(B2-A2)>0, MINUTE(B2-A2) & » minutes and «,»») & IF(SECOND(B2-A2)>0, SECOND(B2-A2) & » seconds»,»»)
The syntax may seem excessively complicated, but it works 🙂
Alternatively, you can calculate time difference by simply subtracting the start time from the end time (e.g. =B2-A2 ), and then apply the following time format to the cell:
d «days,» h «hours,» m «minutes and» s «seconds»
An advantage of this approach is that your result would be a normal time value that you could use in other time calculations, while the result of the complex formula discussed above is a text value. A drawback is that the custom time format cannot distinguish between zero and non-zero values and ignore the latter. To display the result in other formats, please see How to show time over 24 hours, 60 minutes, 60 seconds.
How to calculate and display negative times in Excel
When calculating the time difference in Excel, you may sometimes get the result as ###### error because the difference is a negative time. But is there a way to show negative times properly in Excel? Of course, there is a way, and even more than one 🙂
Method 1. Change Excel Date System to 1904 date system
The fastest and easiest way to display negative time normally (with a minus sign) is switching to the 1904 date system. To do this, click File > Options > Advanced, scroll down to the When calculating this workbook section and put a tick in the Use 1904 date system box.
Click OK to save the new settings, and from now on negative times will be displayed correctly, like negative numbers:
Method 2. Calculate negative time in Excel with formulas
Is changing Excel’s default Date System is not an option, then you can force negative times to display properly using one of the following formulas:
=IF(A2-B2>0, A2-B2, «-» & TEXT(ABS(A2-B2),»h:mm»))
=IF(A2-B2>0, A2-B2, TEXT(ABS(A2-B2),»-h:mm»))
Both formulas check if the time difference (A2-B2) is greater than 0, and if it is they return that difference. If the time difference is less than zero, the first formula calculates the absolute difference and concatenates the minus sign. The second formula yields exactly the same result by using a negative time format «-h::mm«.
Note. Please keep in mind that unlike the first method that treats negative times as negative numeric values, the result of the TEXT function is always a text string that cannot be used in calculations or other formulas.
Adding and subtracting time in Excel
Basically, there are 2 ways to add and subtract time in Excel:
- Using the TIME function
- Using arithmetic calculations based on the number of hours (24), minutes (1440) and seconds (86400) in one day
The TIME(hour, minute, second) function makes Excel time calculations really easy, however it does not allow adding or subtracting more than 23 hours, or 59 minutes, or 59 seconds. If you are working with bigger time intervals, then use one of the arithmetic calculations demonstrated below.
How to add or subtract hours to time in Excel
To add hours to a given time in Excel, you can use one the following formulas.
TIME function to add under 24 hours
For example, if your start time is in cell A2, and you want to add 2 hours to it, the formula is as follows:
Note. If you try adding more than 23 hours with the TIME function, the specified hours will be divided by 24 and the remainder will be added to the start time value. For example, if you try to add 25 hours to «6/2/2015 10:00 AM» (cell A4) using the formula =A4 + TIME(25, 0, 0) , the result will be «06/02/2015 11:00», i.e. A4 + 1 hour.
Formula to add any number of hours (under or over 24 hours)
The following formula has no limitations to the number of hours you want to add:
For example, to add 28 hours to the start time in cell A2, enter the following formula:
To subtract hours from a given time, you use analogous formulas, and just replace «+» with the minus sign:
For example, to subtract 3 hours from the time in cell A2, either of the following formulas will do:
To subtract more than 23 hours, use the first one.
How to add / subtract minutes to time in Excel
To add minutes to a given time, employ the same techniques that we’ve just used for adding hours.
To add or subtract under 60 minutes
Use the TIME function and supply the minutes you want to add or subtract in the second argument:
And here are a couple of real-life formulas to calculate minutes in Excel:
To add 20 minutes to the time in A2: =A2 + TIME(0,20,0)
To subtract 30 minutes from the time in A2: =A2 — TIME(0,30,0)
To add or subtract over 60 minutes
In your calculation, divide the number of minutes by 1440, which is the number of minutes in a day, and add the quotient to the start time:
To subtract minutes from time, simply replace plus with the minus sign. For example:
To add 200 minutes: =A2 + (200/1440)
To subtract 300 minutes: =A2 -(300/1440)
How to add / subtract seconds to a given time
Second calculations in Excel are done in a similar fashion.
To add under 60 seconds to a given time, you can use the TIME function:
To add more than 59 seconds, use the following formula:
To subtract seconds, utilize the same formulas with the minus sign (-) instead of plus (+).
In your Excel worksheets, the formulas may look similar to these:
To add 30 seconds to A2: =A2 + TIME(0,0,31)
To add 1200 seconds to A2: =A2 + (1200/86400)
To subtract 40 seconds from A2: =A2 — TIME(0,0,40)
To subtract 900 seconds from A2: =A2 — (900/86400)
How to sum time in Excel
The Excel sum time formula is the usual SUM function, and applying the proper time format to the result is what does the trick.
Supposing you have a few project times in column B and you want to add them up. You write a simple SUM formula like the one below and get the result in the default format such as hh:mm:ss.
In some cases the default time format works just fine, but sometimes you may want more, for example to display the total time as minutes and seconds, or seconds only. The good news is that no other calculations are required, all you have to do is apply custom time format to the cell with the SUM formula.
Right click the cell and select Format Cells in the context menu, or press Ctrl + 1 to open the Format Cells dialog box. Select Custom from the Category list and type one of the following time formats in the Type box:
- To display total time as minutes and seconds: [m]:ss
- To display total time as seconds: [ss]
The result will look as follows:
How to sum over 24 hours in Excel
In order to add up more than 24 hours, you use the same SUM formula as discussed above, and apply one of the following time formats to the cell:
Format | Displays as | Explanation |
[h]:mm | 30:10 | Hours and minutes |
[h]:mm:ss | 30:10:20 | Hours, minutes and seconds |
[h] «hours», mm «minutes», ss «seconds» | 30 hours, 10 minutes, 20 seconds | |
d h:mm:ss | 1 06:10:20 | Days, hours, minutes and seconds |
d «day» h:mm:ss | 1 day 06:10:20 | |
d «day,» h «hours,» m «minutes and» s «seconds» | 1 day, 6 hours, 10 minutes and 20 seconds |
To see how these custom time formats may look like in your Excel worksheet, please have a look at the screenshot below, where the same SUM formula is entered in cells A9 to A13:
Note. The above custom time formats work for positive values only. If the result of your time calculations is a negative number, e.g. when you are subtracting a bigger time from a smaller time, the result will be displayed as #####. To display negative times differently, please see custom format for negative time values.
Also, please keep in mind that the time format applied to a cell changes only the display presentation without changing the cell’s value. For example, in the screenshot above, cell A13 looks like text, but in fact it’s a usual time value, which is stored as a decimal in the internal Excel system. Meaning, you are free to refer to that cell in other formulas and calculations.
Date & Time Formula Wizard — quick way to calculate times in Excel
Now that you know a bunch of different formulas to add and subtract times in Excel, let me show you the tool that can do it all. Okay, almost all 🙂
Here comes Ablebit’s Date & Time Formula Wizard for Excel:
In the Date & Time Wizard dialog window, you switch to the Add or Subtract tab, depending on which operation you want to perform, and do the following:
- Click the Show time fields link in the left part of the window.
- Supply values or cell references for the formula arguments. As you fill in the argument boxes, the wizard builds the formula in the selected cell.
- When finished, click the Insert Formula
That’s it! For example, this is how you can add the specified number of hours, minutes and seconds to the time in A4:
If you need to copy the formula to other cells, fix all references except the cell containing the original time (A4) with the $ sign like shown in the screenshot below (by default, the wizard always uses relative references). Then double-click the fill handle to copy the formula down the column and you are good to go!
Besides time calculations, the wizard can also add and subtract dates, get the difference between two dates, and calculate age from the birthdate.
If you are curious to try this tool in your own worksheets, you are welcome to download the evaluation version of our Ultimate Suite below.
This is how you calculate time in Excel worksheets. To learn other ways to manipulate dates and times in Excel, I encourage you to check out the resources at the end of this article. I thank you for reading and hope to see you on our blog next week!
Источник
In the example shown, the goal is to enter a valid time based on days, hours, and minutes, then display the result as total hours.
The key is to understand that time in Excel is just a number. 1 day = 24 hours, and 1 hour = 0.0412 (1/24). That means 12 hours = 0.5, 6 hours = 0.25, and so on. Because time is just a number, you can add time to days and display the result using a custom number format, or with your own formula, as explained below.
In the example shown, the formula in cell F5 is:
=B5+TIME(C5,D5,0)
On the right side of the formula, the TIME function is used to assemble a valid time from its component parts (hours, minutes, seconds). Hours come from column C, minutes from column D, and seconds are hardcoded as zero. TIME returns 0.5, since 12 hours equals one half day:
TIME(12,0,0) // returns 0.5
With the number 1 in C5, we can simplify the formula to:
=1+0.5
which returns 1.5 as a final result. To display this result as total hours, a custom number format is used:
[h]:mm
The square brackets tell Excel to display hours over 24, since by default Excel will reset to zero at each 24 hour interval (like a clock). The result is a time like «36:00», since 1.5 is a day and a half, or 36 hours.
The formula in G5 simply points back to F5:
=F5
The custom number format used to display a result like «1d 12h 0m» is:
d"d" h"h" m"m"
More than 31 days
Using «d» to display days in a custom number format works fine up to 31 days. However, after 31 days, Excel will reset days to zero. This does not affect hours, which will continue to display properly with the number format [h].
Unfortunately, a custom number format like [d] is not supported. However, in this example, since days, hours, and minutes are already broken out separately, you can write your own formula to display days, minutes, and hours like this:
=B5&"d "&C5&"h "&D5&"m"
This is an example of concatenation. We are simply embedding all three numeric values into single text string, joined together with the ampersand (&) operator.
If you want to display an existing time value as a text string, you can use a formula like this:
=INT(A1)&" days "&TEXT(A1,"h"" hrs ""m"" mins """)
where A1 contains time. The INT function simply returns the integer portion of the number (days). The TEXT function is used to format hours and minutes.
Dates 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(year, month, day)
=TIME(hours, minutes, seconds)
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:
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 9 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:
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:
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.INTL. NETWORKDAYS.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_date, end_date, and [holidays] inputs work just like the normal WORKDAY function.
The [weekend] input has the following options:
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:
For 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:
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:
This is how TIMEVALUE responds to various time_text inputs:
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:
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:
A Common Problem
One issue people frequently run into is that Excel occasionally misinterprets text fields as dates. An example is here:
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 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…
The objective of this post is to teach you how Excel handles date and time and provide you with all the tools you will need.
It’s designed to be read in conjunction with the accompanying Excel file, which you can download below.
Download the Files
Enter your email address below to download the comprehensive Excel workbook and PDF.
By submitting your email address you agree that we can email you our Excel newsletter.
Regional Settings
When reading this post keep in mind that my regional settings format dates as dd/mm/yyyy and so the screenshots throughout this post are in this format. However, if you open the accompanying Excel file you may see some dates have switched to match your regional settings, which may be different to mine e.g. mm/dd/yyyy.
Dates and times with a format that begins with an asterisk (*) automatically update based on your PC’s regional settings. You can see an example in the Format Cells dialog box below:
Ok, let’s crack on.
Excel Date and Time 101
Excel stores dates and time as a number known as the date serial number, or date-time serial number.
When you look at a date in Excel it’s actually a regular number that has been formatted to look like a date. If you change the cell format to ‘General’ you’ll see the underlying date serial number.
The integer portion of the date serial number represents the day, and the decimal portion is the time. Dates start from 1st January 1900 i.e. 1/1/1900 has a date serial number of 1.
Caution! Excel dates after 28th February 1900 are actually one day out. Excel behaves as though the date 29th February 1900 existed, which it didn’t.
Microsoft intentionally included this bug in Excel so that it would remain compatible with the spreadsheet program that had the majority market share at the time; Lotus 1-2-3.
Lotus 1-2-3 was incorrectly programmed as though 1900 was a leap year. This isn’t a problem as long as all your dates are later than 1st March 1900.
Excel gives each date a numeric value starting at 1st January 1900. 1st January 1900 has a numeric value of 1, the 2nd January 1900 has a numeric value of 2 and so on. These are called ‘date serial numbers’, and they enable us to do math calculations and use dates in formulas.
The Date Serial Number column displays the Date column values in their date serial number equivalent.
e.g. 1/1/2017 has a date serial number of 42736. i.e. 1st January 2017 is 42,736 days since 31st December 1899.
Tip: format the date serial number column as a Date and you’ll see they look the same as the Date column values.
Time
Times also use a serial number format and are represented as decimal fractions.
Hours: since 24 hours = 1 day, we can infer that 24 hours has a time serial number of 1, which can be formatted as time to display 24:00 or 12:00 AM or 0:00. Whereas 12 hours or the time 12:00 has a value of 0.50 because it is half of 24 hours or half of a day, and 1 hour is 0.41666′ because it’s 1/24 of a day.
Minutes: since 1 hour is 1/24 of a day, and 1 minute is 1/60 of an hour, we can also say that 1 minute is 1/1440 of a day, or its time serial number is 0.00069444′
Seconds: since a second is 1/60 of a minute, which is 1/60 of an hour, which is 1/24 of a day. We can also say one second is 1/86400 of a day or in time serial number form it’s 0.0000115740740740741…
Date & Time Together
Now that we know how dates and times are stored we can put them together — ddddd.tttttt
For example, the date and time of 1st January 2012 10:00:00 AM has a date-time serial value of 40909.4166666667
40909 being the serial value representing the date 1st January 2012, and .4166666667 being the decimal value for the time 10:00 AM and 00 seconds.
More examples below.
Entering Dates & Times in Excel
Entering Dates
You can type in various configurations of a date and Excel will automatically recognise it as a date and upon pressing ENTER it will convert it to a date serial number and apply a date format on the cell.
For example, try typing (or even copy and paste) the following dates into an empty cell:
1-1-2009 |
1-1-09 |
1/1/2009 |
1/1/09 |
1-Jan-09 |
1-Jan 09 |
1-Jan-2009 |
1 Jan 09 |
1/1 |
You can see in the table above that entering numbers that look like dates and are separated by a forward slash or hyphen will be recognised as a date. Even typing in a date with the month name gets converted to a date.
However, dates separated with a period like this 1.1.2009, or with spaces between numbers like this 01 01 2009, will end up as text, not a date. Gotta have some limits!
Tip: Dates that display ##### in a cell usually indicate that the column is simply not wide enough to display it.
However, if you make the cell really wide and it still displays ##### then this indicates that the date is a negative value and Excel can’t display negative dates.
Entering Dates with Two Digit Years
When you enter a date with two digits for the year e.g. 1/1/09, Excel has to decide if you mean 2009 or 1909.
It goes by the rule that dates with years 29 or before, are treated as 20xx and dates with the year 30 or older are treated as 19xx. See examples below.
Tip: You can enter the day and month portions of a date and Excel will insert the year based on your computer’s clock. Nice to know for data entry.
Entering Time
When you enter time you must follow a strict format of at least h:mm. i.e. the hour and minutes are separated by a colon with no spaces either side. Entering the h:mm components will result in a time formatted in military time e.g. 2:00 PM is 14:00 in military time.
If you enter a time that includes a seconds component e.g. 3:15:40, Excel will automatically format the cell in h:mm:ss.
If you want the time to be formatted with AM/PM you can simply enter a space after the time and then type AM or PM, or apply the number format to the cell later. Here are some examples:
Entering Dates & Time Together
Now that we know how to enter dates and time separately we can put them together to enter a date and time in the same cell.
You can even enter time then date and Excel will fix the order for you.
You’ll find that even if you enter AM/PM, that Excel will convert it to military time by default. You can override this with a custom number format. More on that later.
Simple Date & Time Math
Now that we understand that Excel stores dates and time as serial numbers, you’ll see how logical it is to perform math operations on these values. We’ll look at some simple examples here and tackle the more complex scenarios later when we look at Date and Time Functions.
Adding/Subtracting Days from Dates
Tip: you can also add/subtract the days directly in the formula e.g. =B10+10 or =B11-5 Although, it’s better to place the values you’re adjusting by in their own cell or a named range.
Subtracting Dates from one another
Tip: format the cell to General or Number to see the number of days between two dates.
Note: the ‘result’ is exclusive of the start day i.e. it assumes the start day is at the end of that day.
Adding Times to one another
The time being added is input as a time serial number. Notice there are no negative times in the table below. Remember we can’t display negative times. Instead we need to use the math operator to tell Excel to subtract time. See examples below.
Note: Times that roll over to the next day result in a time-date serial number >= 1. Cell E28 actually contains a time-serial number of 1.08333′, but since the cell is formatted to display time formatted as h:mm:ss, only the time portion is visible.
If you want to show the cumulative time (like cell E29) then you need to surround the ‘h’ part of the time format in square brackets like so: [h]:mm:ss
Subtracting Time from Times
Notice the last result in the table below shows ######, this is because it results in a negative time and Excel can’t display that, but notice it can return a negative time serial number. More on how to solve this later.
Subtracting Times from one another
Again, here the last result shows ###### because it results in a negative time.
Excel Date and Time Shortcuts
‘Good to Know’ Stuff about Excel Date and Time
— Dates prior to 1st January 1900 are not recognised in Excel.
— A negative date will display in the cell as #######
— Times stored without a date effectively inherit the date 0 Jan 1900 i.e. the month is Jan and the year 1900 and the day is zero. Remember, there are no dates prior to 1/1/1900 from Excel’s perspective. This means that times stored without a date e.g. 0.50 for 12:00 PM is the equivalent of 0 Jan 1900 12:00 PM.
This is important because if you try to take 14 hours from 12 hours (without a date) you’ll get the dreaded ###### display in the cell, because negative dates and times cannot be displayed. We’ll cover workarounds for this later, but for now keep in mind that math on dates and time that result in negative date-time serial numbers cannot be formatted as a date.
Date Modes
— Excel actually has two date modes. The other mode is called 1904 Date System and is used for compatibility with Excel 2008 for Mac and earlier Mac versions. You can change the date system in the Advanced Options.
In the 1904 date system dates are calculated using 1st January 1904 as the starting point. The difference between the two date systems is 1,462 days. This means that the serial number of a date in the 1900 date system is always 1,462 days greater than the serial number of the same date in the 1904 date system. 1,462 days is equal to four years and one day (including one leap day).
Caution; the date setting you choose applies to all dates within the workbook. You can’t mix and match modes and you shouldn’t reference workbooks that use a different date system in formulas.
Bottom line; don’t use the 1904 date system unless absolutely necessary! Click here for more on date systems in Excel.
— Excel applies date number formats based on your system region settings. For example, my system is set to display dates in dd/mm/yyyy format, but if you’re in the U.S. your system is likely to format them as mm/dd/yyyy. Excel will automatically convert the format of date serial numbers to suit your system settings as long as it’s one of the default date formats and not a custom number format.
More Excel Date and Time Tips
This post is just the beginning, the next steps in mastering Excel Date and Time are below:
- Every Excel Date and Time Function explained
- Formatting Date and Time in Excel
- Common Date and Time Calculations
Tip: Avoid waiting, download the workbook and get the above topics now.
Enter your email address below to download the comprehensive Excel workbook and PDF.
By submitting your email address you agree that we can email you our Excel newsletter.