Google Sheets Tips

Date functions in Google Sheets: DATE, DATEVALUE, DATEDIF, EDATE and EPOCHTODATE

DATE builds a date from a year, a month and a day. DATEVALUE converts a text into a date. DATEDIF counts the years, months or days between two dates. EDATE moves a date by a number of months, and EPOCHTODATE converts a Unix timestamp. This guide shows the syntax and tested behaviour of each, with the units of DATEDIF and the errors to expect.

Google Sheets TipsVadym Kramarenko10 min read

Date functions in Google Sheets: DATE, DATEVALUE, DATEDIF, EDATE and EPOCHTODATE

Five functions cover most date work in Google Sheets:

Function What it does Example Result
DATE(year, month, day) Builds a date from three numbers =DATE(2024, 3, 1) 1 March 2024
DATEVALUE(date_text) Converts a text into a date =DATEVALUE("2024-09-15") 15 September 2024
DATEDIF(start, end, unit) Counts years, months or days between two dates =DATEDIF(DATE(2020,1,15), DATE(2024,3,1), "Y") 4
EDATE(start, months) Moves a date by a number of months =EDATE(DATE(2024,1,31), 1) 29 February 2024
EPOCHTODATE(timestamp, [unit]) Converts a Unix timestamp into a date and time =EPOCHTODATE(1579046400) 15 January 2020, 00:00

A date in Sheets is a number: the count of days since 30 December 1899. That is why dates can be subtracted and compared, and why a date function sometimes shows a number such as 45000 until the cell is given a date format (Format > Number > Date). The guide to dates and times explains the storage in detail.

DATE: build a date

DATE: build a date

=DATE(year, month, day)

=DATE(D3, E3, F3)

Google Sheets with hire year, month and day in three columns and the formula =DATE(D3,E3,F3) returning the hire date 01/03/2020

DATE is the safe way to write a date inside a formula, because it does not depend on the locale of the spreadsheet the way a typed “3/1/2024” does. Three behaviours are worth knowing:

  • Overflow is carried over. =DATE(2024, 14, 1) returns 1 February 2025, and =DATE(2024, 2, 30) returns 1 March 2024. This makes arithmetic easy: =DATE(YEAR(A2), MONTH(A2) + 1, 1) is the first day of the next month, also in December.
  • Use four digits for the year. =DATE(24, 1, 1) returns a date in 1924.
  • The result is a real date. It can be subtracted from another date or compared with TODAY.

Days until a date

=DATE(D3, E3, F3) - TODAY()

Google Sheets with an end year, month and day in three columns and the formula =DATE(D3,E3,F3) - TODAY() returning the number of days left

Subtracting two dates gives the days between them. TODAY changes every day, so the result counts down by itself.

Weekday or weekend

=IF(OR(WEEKDAY(DATE(D3, E3, F3))=1, WEEKDAY(DATE(D3, E3, F3))=7), "Weekend", "Weekday")

Google Sheets with a formula built from IF, OR, WEEKDAY and DATE labeling each date as Weekday or Weekend

WEEKDAY returns 1 for Sunday and 7 for Saturday. A shorter form of the same test is =IF(WEEKDAY(A2, 2) > 5, "Weekend", "Weekday"), where the second argument makes Monday day 1.

DATEVALUE: convert text into a date

DATEVALUE: convert text into a date

=DATEVALUE(date_text)

Dates that arrive as text (left-aligned, not sortable as dates) are converted with DATEVALUE.

=DATEVALUE(D3)

Google Sheets with hire dates written as text in several layouts and the formula =DATEVALUE(D3) returning 01/15/2020 in the first row and serial numbers such as 43261 below

The first result has a date format; the others show the underlying serial numbers. They are correct dates, waiting for a format.

DATEVALUE reads the layouts that Sheets itself understands in the locale of the spreadsheet: “2024-09-15”, “15 August 2024”, “12/10/2023”. A text without a year gets the current year:

=DATEVALUE(E3)

Google Sheets with texts such as 03/01, December 10 and 15 August and the formula =DATEVALUE(E3) returning dates in the year in which the sheet was calculated

A text it cannot read returns #VALUE!. “October 5th” fails because of the “th”:

Google Sheets with a #VALUE! error and the message that the DATEVALUE parameter October 5th cannot be parsed to date/time

Two limits:

  • An ambiguous text such as “03/04/2024” is read by the locale: 4 March in the United States, 3 April in most of Europe. If the source used the other order, DATEVALUE returns a valid but wrong date, without an error. Rebuild such dates from their parts with DATE and LEFT, RIGHT and MID.
  • DATEVALUE drops the time. For a text with a time, add TIMEVALUE: =DATEVALUE(A2) + TIMEVALUE(A2).

A date inside a longer text

=DATEVALUE(MID(D3, 11, 10))

For “Hired on: 2019-12-29”, MID takes ten characters starting from the eleventh, “2019-12-29”, and DATEVALUE converts them. Count the start position carefully: one character too early and the last digit of the day is cut off, which still gives a valid date, the wrong one.

The Turning Point

OWOX Data Marts

See your first report built in real time. 15 minutes.

  1. Connect your data warehouse
  2. Pick your metrics
  3. Get a live Google Sheets report

In the time it takes to write a ticket. Then imagine never writing that ticket again.

Book a Demo

We'll use your actual use case

DATEDIF: years, months and days between two dates

DATEDIF: years, months and days between two dates

=DATEDIF(start_date, end_date, unit)

The unit decides what is counted. For 15 January 2020 to 1 March 2024:

Unit Counts Result
"Y" Complete years 4
"M" Complete months 49
"D" Days 1507
"YM" Months left after the complete years 1
"MD" Days left after the complete months 15
"YD" Days, as if both dates were in the same year 46

The start date has to come first. If it is later than the end date, DATEDIF returns #NUM!.

Days

=DATEDIF(D3, E3, "D")

Google Sheets with hire dates in column D, contract end dates in column E and the formula =DATEDIF(D3, E3, “D”) returning 3,653 days in the first row

With “D”, DATEDIF gives the same number as subtracting the dates, =E3-D3, or as DAYS. Counted up to today:

=DATEDIF(D3, TODAY(), "D")

Google Sheets with hire dates in column D and the formula =DATEDIF(D3, TODAY(), “D”) returning the days since each hire date

These are calendar days. For working days, use NETWORKDAYS.

Months

=DATEDIF(D3, F3, "M")

Google Sheets with hire dates and last promotion dates and the formula =DATEDIF(D3, F3, “M”) returning 25 months in the first row

Only complete months count: from 15 January to 14 March is one month, from 15 January to 15 March two.

Tenure or age in years, months and days

Three formulas with three units give the full breakdown:

=DATEDIF(D3, TODAY(), "Y")

Google Sheets with hire dates and three result columns for years, months and days; the formula with the Y unit returns the complete years

=DATEDIF(D3, TODAY(), "YM")

Google Sheets with the formula =DATEDIF(D3, TODAY(), “YM”) returning the months left after the complete years

=DATEDIF(D3, TODAY(), "MD")

Google Sheets with the formula =DATEDIF(D3, TODAY(), “MD”) returning the days left after the complete months

Joined into one text:

=DATEDIF(D3, TODAY(), "Y") & " years, " & DATEDIF(D3, TODAY(), "YM") & " months, " & DATEDIF(D3, TODAY(), "MD") & " days"

The same formula with a birth date returns an age. =DATEDIF(A2, TODAY(), "Y") alone is the age in whole years.

Days since the last anniversary

=DATEDIF(D3, TODAY(), "YD")

Google Sheets with hire dates and the formula =DATEDIF(D3, TODAY(), “YD”) returning the days since the last anniversary of each hire date

A whole column

=ARRAYFORMULA(DATEDIF(D3:D12, TODAY(), "D"))

Google Sheets with hire dates in D3:D12 and the formula =ARRAYFORMULA(DATEDIF(D3:D12, TODAY(), “D”)) returning the days since each of them

EDATE: add or subtract months

EDATE: add or subtract months

=EDATE(start_date, months)

=EDATE(E3, 6)

Google Sheets with last promotion dates in column E and the formula =EDATE(E3, 6) returning the date six months later, 09/01/2022 for 03/01/2022

A negative number goes back: =EDATE(E3, -3). EDATE keeps the day of the month, and when the target month is shorter, it returns its last day: one month after 31 January 2024 is 29 February 2024. For years, multiply: =EDATE(A2, 12) is the same day next year.

EDATE is the right tool for renewal dates, trial ends and review dates, where “plus 30 days” would drift.

The length of a period that starts on a date

=EDATE(D3, 1) - D3

Google Sheets with hire dates in column D and the formula =EDATE(D3, 1) - D3 returning 31, 30 or 28 days

The result is the number of days from the date to the same day next month. For the last day of a month, use EOMONTH.

EPOCHTODATE: convert a unix timestamp

EPOCHTODATE: convert a unix timestamp

=EPOCHTODATE(timestamp, [unit])

  • timestamp: a Unix timestamp, the time elapsed since 1 January 1970, 00:00 UTC.
  • unit: optional. 1, the default, for seconds; 2 for milliseconds; 3 for microseconds.

=EPOCHTODATE(E3)

Google Sheets with Unix timestamps in seconds in column E and the formula =EPOCHTODATE(E3) returning 01/15/2020 0:00:00 for 1579046400

Timestamps from APIs and logs are often in milliseconds, three digits longer. Set the unit to 2:

=EPOCHTODATE(E3, 2)

Google Sheets with timestamps in milliseconds and the formula =EPOCHTODATE(E3, 2) returning the same dates

The result is in UTC, not in the time zone of the spreadsheet. To shift it, add the offset as a fraction of a day: =EPOCHTODATE(E3) + 2/24 for UTC+2.

The reverse, from a date to a timestamp in seconds:

=(D3 - DATE(1970,1,1)) * 86400

Show a date in another format

Show a date in another format

A date function returns a number with a date format. To write the date in a specific layout inside a text or a label, use TEXT:

=TEXT(E3, "DD MMMM, YYYY")

Google Sheets with contract end dates in column E and the formula =TEXT(E3, “DD MMMM, YYYY”) returning texts such as 15 January, 2030

The result of TEXT is a text: good for display, not for further date arithmetic.

Errors with date functions

Errors with date functions

⚠️ Error: #VALUE!

✅ Solution: A text could not be read as a date: an ordinal such as “5th”, a month name in another language than the spreadsheet’s locale, or a stray character. Clean the text or rebuild the date with DATE.

⚠️ Error: #NUM! in DATEDIF.

✅ Solution: The start date is later than the end date, or the unit is not one of “Y”, “M”, “D”, “YM”, “MD”, “YD”.

⚠️ Error: A number such as 45000 appears where a date should be.

✅ Solution: The value is a date without a date format. Apply Format > Number > Date.

⚠️ Error: The date is valid, but the day and the month are swapped.

✅ Solution: A text date was read in the wrong order for its source. Check File > Settings > Locale, or build the date from its parts.

⚠️ Error: A date lands in the 1900s.

✅ Solution: The year was given with two digits. Use four.

⚠️ Error: A timestamp converts to a date in 1970 or far in the future.

✅ Solution: The unit does not match: seconds were read as milliseconds or the other way round. Count the digits; a current timestamp has 10 digits in seconds and 13 in milliseconds.

Related Google Sheets functions

Dates break at the border between systems

Dates break at the border between systems

Most date problems in a sheet are import problems: an export writes dates as text, in the order of another locale, or as Unix timestamps, and DATEVALUE and EPOCHTODATE are used to repair them. The repair has to be repeated with every export, and one file read in the wrong locale puts April where March should be without any error.

The OWOX Data Marts extension for Google Sheets covers that half. A data analyst publishes a data mart (a table or an SQL query in your data warehouse) and makes it available for reports. In Sheets you open the extension, pick the data mart, tick the columns you want and run it. The rows land in a tab, ready for your formulas.

Google Sheets with the OWOX Data Marts extension open beside an ad spend table: the Unified Ad Spend data mart, nine of fourteen columns ticked and a Save & Run button – the rows in the sheet come from a governed data mart, not a pasted export

What changes for the person who maintains the sheet:

  • Refresh replaces re-export. Refresh current report in the extension menu re-runs the same pull, and a scheduled refresh keeps the tab current without anyone touching it.
  • The source is written on the sheet. The header cell of an imported tab carries a note with the data mart it came from, the time of the import and a link to the report.
  • No SQL and no warehouse access needed. The analyst decides which data marts and columns are available. You choose from that list.

The extension does not write or change the analyst’s SQL. The conversion from text and timestamps is then written once in that SQL instead of in every sheet, and the date functions here are left for calculations. The extension comes with the OWOX Cloud plans of OWOX Data Marts; spreadsheet reporting describes both ways data reaches a sheet.

Your New Normal

Turn your data into decisions.

Governed data marts give you the clean foundation ML needs to actually work.

  • No AI hallucinations
  • Analyst-governed definitions
  • Every number traces to SQL
Get started free

FAQ

Frequently Asked Questions

What is the EPOCHTODATE function?

EPOCHTODATE converts a Unix timestamp, the time elapsed since 1 January 1970 00:00 UTC, into a date and time. The syntax is EPOCHTODATE(timestamp, [unit]): unit 1, the default, reads the timestamp as seconds, 2 as milliseconds and 3 as microseconds. For example, EPOCHTODATE(1579046400) returns 15 January 2020, 00:00. The result is in UTC.

What is the EDATE function for?

The EDATE function is used to add or subtract a specific number of months from a given date. The syntax is:=EDATE(start_date, number_of_months)For example,=EDATE(A1, 3)It will calculate the date that is three months after the date in cell A1. It helps calculate future or past dates based on months.

Can I convert text to a date format?

Yes, you can convert text to a date format in Google Sheets by using the DATEVALUE function. This function takes a text string and converts it to a date. For example:=DATEVALUE("2024-09-15")It will convert the string "2024-09-15" into a date value

How do I calculate the number of days between two dates in Google Sheets?

You can use the DATEDIF function to calculate the number of days between two dates. The syntax is:=DATEDIF(start_date, end_date, "D")Here, "D" stands for days. For example: =DATEDIF(A1, B1, "D")It will return the number of days between the dates in cells A1 and B1.

Who wrote this

Vadym Kramarenko

Vadym Kramarenko · Growth Marketing Manager

Vadym Kramarenko is a Growth Marketing Manager at OWOX, where he drives user acquisition and product-led growth strategies. He hosts the OWOX podcast, interviewing analytics professionals about data-driven marketing, attribution, and reporting best practices. Vadym specializes in turning complex analytics concepts into practical, actionable marketing frameworks.