Advanced Tips for Using the DATEVALUE Function in Google Sheets

Published on

The DATEVALUE function in Google Sheets is designed to convert a date string into a serial date value. However, it also serves two other key purposes:

  1. Replacing the ISDATE drag-down formula or the alternative MAP + ISDATE combination.
  2. Simplifying the use of date conditions in the QUERY function.

A date value in Google Sheets is a number representing the number of days since December 30, 1899. For example, the DATEVALUE function returns 1 for the date string “1899-12-31” and 2 for “1900-01-01”.

Syntax of the DATEVALUE Function

The syntax of the DATEVALUE function in Google Sheets is:

DATEVALUE(date_string)

Where date_string is a text string that represents a date. If you hardcode the date string, it must be enclosed in double-quotes.

Example:

=DATEVALUE("05/09/23")

The date_string can be in any format that Google Sheets recognizes. Here are some examples of valid date string formats:

  • 05/09/23
  • Tue, 05 09 23
  • Tue, 5 Sep 2023
  • 2023-09-05
  • 5 Sep 2023
  • 5-Sep-2023
  • 05/09
  • Tuesday, 5 September 2023
  • Tuesday, 5 September 2023, 10:10:30
  • 13:25 (time only)

When interpreting a date string, Google Sheets uses the Locale setting, determining whether the format is MM/DD/YYYY or DD/MM/YYYY. For instance, the date string “05/09/2023” may be interpreted as May 9, 2023, or September 5, 2023, depending on your Locale. You can check your locale’s date formatting by entering the =TODAY() function in a new sheet.

Exception: If the date string contains a month in text format, like “5 Sep 2023”, there won’t be an issue with different date formats.

Examples

In the following example, I’ve used the DATEVALUE function to convert date strings in the range A3:A11 into date values:

Examples of formulas using the DATEVALUE function in Google Sheets

To convert a single date string (cell A3) to a date value, use:

=DATEVALUE(A3)

To apply the formula to a range of cells at once, use the following array formula in B3:

=ARRAYFORMULA(DATEVALUE(A3:A11))

This converts all date strings in the range A3:A11.

How to Convert DATEVALUE to Date Format in Google Sheets

There are two ways to convert a serial number back to a readable date format:

  1. Using the TO_DATE Function
    The TO_DATE function converts a date serial number into a date.

Syntax:

TO_DATE(value)

For example, to convert the serial number returned by the DATEVALUE function back to a date:

=TO_DATE(DATEVALUE("Tue, 5 Sep 2023"))

When converting a range of serial numbers, wrap the TO_DATE function in ARRAYFORMULA:

=ARRAYFORMULA(TO_DATE(DATEVALUE(A3:A11)))
  1. Using Number Formatting
    Alternatively, you can format the serial number using Format > Number > Date in the menu.

Other Uses of the DATEVALUE Function

  1. Replacing ISDATE and MAP with DATEVALUE
    The ISDATE function checks if a cell contains a valid date, time, or timestamp and returns TRUE or FALSE.

Syntax:

ISDATE(value)
Examples of comparing ISDATE with DATEVALUE in Google Sheets

If you want to apply ISDATE to a range of cells, you typically combine it with the MAP function:

=MAP(A3:A9, LAMBDA(r, ISDATE(r)))
Example of ISDATE with MAP and LAMBDA in Google Sheets

Alternatively, the DATEVALUE function can be used to achieve this and distinguish between dates and times.

=ARRAYFORMULA(IFERROR(DATEVALUE(A3:A9), -1) >= 0)

This formula returns TRUE for valid dates and FALSE for invalid date strings or times.

If you need to return FALSE for cells containing only time (without a date), use:

=ARRAYFORMULA(IFERROR(DATEVALUE(A3:A9), -1) > 0)

Key Difference: The ISDATE function will return TRUE if the cell contains a number formatted as a date (e.g., formatted as ‘Sunday’). In contrast, DATEVALUE will return an error if the text cannot be converted to a date.

  1. Simplifying Date Conditions in QUERY with DATEVALUE
    Handling date literals in the QUERY function can be tricky. Using the DATEVALUE function simplifies this process.

Assume you have an expense sheet with dates in column A, expense types in column B, and beneficiary names in column C. To filter the data between two dates in cells E2 and E3, you would typically use a QUERY formula like:

=QUERY({A2:C}, "Select * where Col1 > date '"&TEXT(E2,"yyyy-mm-dd")&"' and Col1 < date '"&TEXT(E3,"yyyy-mm-dd")&"' ")

However, using DATEVALUE, you can simplify the formula:

=ARRAYFORMULA(QUERY(HSTACK(DATEVALUE(A2:A), B2:C), "Select * where Col1 > "&E2&" and Col1 < "&E3&" "))

This method allows the use of number literals for date comparisons. Alternatively, you can apply Format > Number > Number to column A and use:

=QUERY(A2:C, "Select * where Col1 > "&E2&" and Col1 < "&E3&"")

Conclusion

The DATEVALUE function in Google Sheets is a versatile tool for converting date strings into serial date values. We’ve seen its core uses, along with tips to replace the ISDATE function and simplify date queries.

One final tip: many Google Sheets functions, like SEQUENCE, can automatically generate date values. For example, the following formula returns 31 date values starting from January 1, 2023:

=SEQUENCE(31, 1, "2023-1-1")

You can use the TO_DATE function to convert these serial numbers back into proper dates:

=ARRAYFORMULA(TO_DATE(SEQUENCE(31, 1, "2023-1-1")))

In summary, while other functions return date values, DATEVALUE is the go-to for converting date strings into date values.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Google Sheets: Get the Last Row with Any Data Across Multiple Columns

It’s common to have several empty rows at the bottom of a Google Sheet,...

How to Calculate Digital Root in Google Sheets

The digital root is the single-digit value you get by repeatedly summing the digits...

How to Build an Advanced Book Tracker in Google Sheets: Formulas Explained

If you're tired of forgetting what you've read, which books you rated 5 stars,...

Google Sheets Reading List Tracker Template (Free Download)

Looking for a smarter, more visual way to manage your reading goals? This Google...

More like this

Google Sheets: Get the Last Row with Any Data Across Multiple Columns

It’s common to have several empty rows at the bottom of a Google Sheet,...

How to Calculate Digital Root in Google Sheets

The digital root is the single-digit value you get by repeatedly summing the digits...

How to Build an Advanced Book Tracker in Google Sheets: Formulas Explained

If you're tired of forgetting what you've read, which books you rated 5 stars,...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.