See Sanity in action 👀 Join us for a live product demo + Q&A →

How to Order by a Nullable Datefield

3 replies
Last updated: Jan 17, 2023
How do I go about ordering by a nullable datefield?

|order(nullable desc)
returns the null values first
|order(defined(nullable) desc)
works but it only orders if it’s defined and not the date
Jan 12, 2023, 8:17 AM
Talking to the rubber duck helped me here,
Can do:

|order(defined(nullable) desc, nullable desc)
Jan 12, 2023, 8:22 AM
Rubber duck debugging FTW 🙌
Jan 12, 2023, 11:05 AM
Jan 17, 2023, 8:51 PM – build remarkable experiences at scale

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

Categorized in