Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Does the `dateTime()` Function in GROQ Require the `Datetime` or `Date` Data Types?

3 replies
Last updated: Sep 29, 2022
does anyone know if the
dateTime()
function in GROQ requires the
Datetime
data type, or can it be used with just the
Date
type? I’m getting a null response trying to run the following query
*[_type == "exhibition"]{ "dateTIme": dateTime(startDate) }
where startDate is a
Date
type.
I’m trying to compare two
date
in order to return a specific document within a certain range of dates
Sep 28, 2022, 11:34 PM
It looks like
dateTime
only accepts RFC3339 format strings like:
1985-04-12T23:20:50.52Z
. I was able to get it to work if I did this though:
dateTime(<date-field> + 'T00:00:00Z')
Sep 28, 2022, 11:50 PM
user M
ty! I forgot you could use strings in groq like that!
Sep 29, 2022, 12:08 AM
There's so much GROQ can do that it's easy to forget stuff 😅
Sep 29, 2022, 6:02 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?