Knowledge hub

Date and time in Excel

Dealing with date and time in Excel doesn't usually require a complicated formula — but it can be tricky to get the exact result and format you want.

Formatting date and time in Excel

The easiest way to make sure your cell is in the right format is the dropdown box at the top of the ribbon:

Date format dropdown in Excel

For more options, select your cell(s) and press Ctrl + 1 (or right-click and choose Format Cells).

Format Cells dialog with Date, Time and Custom categories

If you need a very specific format, =TEXT(cell, format) gives you almost any output you want — e.g. "Wednesday-07-2021" or "Wednesday 21-July/2021".

TEXT function formatting a date

And from there you can get as creative as you like:

Custom TEXT function date formatting examples

First/last working day of this month

Last working day of this month:

=IF(1<WEEKDAY(EOMONTH(TODAY(),0))<7,EOMONTH(TODAY(),0),WORKDAY(EOMONTH(TODAY(),0),-1))

Breaking that down:

  • =TODAY() returns today's date, and updates automatically every day the file is opened.
  • =EOMONTH(TODAY(),0) returns the last day of this month.
  • =WEEKDAY(date) returns a number from 1–7 for the day of the week (1 = Sunday, 2 = Monday, ... 7 = Saturday).

In short: if the last day of the month falls Monday–Friday, return it as-is. If it falls on a weekend, return the previous working day.

Formula returning last working day of the month

Day/time difference

Difference in years/months

DATEDIF formula calculating difference in days

=DATEDIF(start date, end date, years/months/days) calculates the difference between two dates. A #NUM error means either the start date is after the end date, or you didn't specify "y", "m", or "d".

Difference in days

Comparing DATEDIF and subtraction for day differences

DATEDIF looks like the obvious choice for day differences, but it's not perfect once time is involved — 10:00am to 9:59am the next day isn't quite one full day, yet DATEDIF will still return 1.

The more reliable approach is subtracting start date from end date directly and wrapping it in INT, which returns the integer part of a number without rounding — =INT(1.99999) returns 1.

Unlike DATEDIF, subtracting dates directly won't throw a #NUM error if the start date is after the end date — you'll just get a negative result. To force a positive number, wrap it in ABS: =ABS(INT(B1-A1))

Difference in time

To calculate the difference between two times, subtract start time from end time. The trick is understanding the result:

Time difference formula in time vs number format

By default the result stays in time format, but you can switch it to Number format. Once you do, remember that in Excel, 1 as a number represents one full day — time is converted to a number as a fraction of 24 hours.

Time-to-number conversion: 6:00am is a quarter of a day, so it's 0.25 as a number. 9:00pm (21:00) is 21 out of 24, so it's 0.88. Multiply a time difference by 24 to convert it into hours as a number — useful for timesheets and further calculations.

####### error

When the end time is before the start time, subtracting in time format gives a ######## error. Converting the result to number format removes it — =(B2-A2)*24 will simply return -0.50.

Hash error from subtracting time in time format

Various formats

StartEndResultFormula
9:0016:597:59=End − Start
9:0016:597.98 hrs=ROUND((End−Start)*24,2)&" hrs"
9:0016:59479 min=ROUND((End−Start)*24*60,2)&" min"
9:0016:597 hours 59 minutes=TEXT(End−Start,"h"" hours ""m"" minutes""")

Adding time/hours together

Adding a number of hours to a start time isn't as simple as it looks — the intuitive approach doesn't work:

Incorrect approach to adding time in Excel

No matter what you add, the result stays 9:00. Since Excel converts time to a fraction of 24 hours, 9:00 + one full day is still 9:00. The fix is converting hours to a fraction of a day first:

Correct formula for adding hours to a time

And this works even when dates are included in the start time:

Adding time correctly including dates

Converting date to number

Dates convert to numbers the same way time does. 01/01/1900 is the earliest valid date in Excel — enter anything earlier and Excel forces it to 0/01/1900, which isn't a real date:

Earliest possible date in Excel as a number

Excel converts dates to numbers by counting days from 01/01/1900 — with 01/01/1900 itself being 1, 02/01/1900 being 2, and so on.

Have a date or time calculation we haven't covered? Let us know and we'll add it.

Get in touch