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

Timezone issue with GROK now() function when filtering by datetime in Sanity editor

5 replies
Last updated: Aug 11, 2020
Another thing that I've noticed is that when I set a datetime in the editor and then try to filter using GROK now() function, there seems to be a 1-hour timezone difference:

*[_type == 'quiz' && publicationDate <= now()]

For example, having set 8 am in the datepicker, the request will only return a result at 9 am. The date I get in the document is correct though so I think the issue is with the
now()
function
Aug 11, 2020, 10:28 AM
What UTC time are you seeing in the
publicationDate
data for the relevant document? If you consider
now()
is UTC, does that correspond to the results?
Aug 11, 2020, 10:34 AM
the
publicationDate
is a ISO8601 string and is correct according to my timezone:
2020-08-11T06:00:00.000Z
(I'm in Paris, UTC+2). So even with
now()
being UTC the results don't make sense
Aug 11, 2020, 10:38 AM
Agreed, that doesn’t make sense. Are you getting any different results if you wrap both
publicationDate
and
now()
in
dateTime()
? As follows:
*[_type == 'quiz' && dateTime(publicationDate) <= dateTime(now())]
Aug 11, 2020, 10:41 AM
That works, thanks!
Aug 11, 2020, 11:01 AM
Awesome, glad to hear!
Aug 11, 2020, 11:03 AM

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?