Join live – Get insights, tips, + Q&A from Sanity developers on our latest releases

Applying custom functions directly in GROQ to destructure data in Sanity.io.

2 replies
Last updated: Oct 10, 2023
HI all, I'm wondering if is there any way apply function to destructure data like hour, year etc. directly in GROQ something like this:

*[_type == "open_course" && is_active == true]{ in_person{
  'year' : new Date(start_date).getFullYear()
 }
}
}
Any gists or ideas as
datetime()
doesn't explain much. It is more about using custom function directly in GROQ to return values I need . Or there is no way to apply such functionality and I have to process data when I receive these from Sanity?
Oct 9, 2023, 11:00 PM
No, that sort of thing will need to be handled wherever you’re consuming your data.
Oct 10, 2023, 3:23 PM
Thank you
user M
, All sorted with utility functions.
Oct 10, 2023, 7:32 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?

Categorized in