🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

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
function in GROQ requires the
data type, or can it be used with just the
type? I’m getting a null response trying to run the following query
*[_type == "exhibition"]{ "dateTIme": dateTime(startDate) }
where startDate is a
I’m trying to compare two
in order to return a specific document within a certain range of dates
Sep 28, 2022, 11:34 PM
It looks like
only accepts RFC3339 format strings like:
. 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?