Sanity date field showing day before selected date
This is a known timezone issue with the date schema type in Sanity Studio v2! The problem you're experiencing is related to how the date type handles timezone conversions.
The date schema type in Sanity stores dates without time information (just the date portion), but browsers and JavaScript Date objects always work with full timestamps including time. When you input a date like 2021-03-09, it's being interpreted as midnight UTC (2021-03-09T00:00:00Z). If you're in a timezone behind UTC (like anywhere in the Americas), when that UTC timestamp is converted to your local timezone for display, it shows as the previous day.
The solution is to use the datetime schema type instead of date:
{
name: 'publishDate',
title: 'Publish Date',
type: 'datetime',
options: {
dateFormat: 'YYYY-MM-DD',
timeFormat: false, // This hides the time picker if you only want dates
timeStep: 15
}
}By using datetime with timeFormat: false, you get a date-only picker in the UI, but it stores the full timestamp which prevents the timezone conversion issue. The date will be stored with your local timezone's midnight, so it displays correctly.
Alternative workaround if you must use date type:
If you need to stick with the date type for some reason, you'll need to handle the timezone offset in your frontend when displaying the date. Make sure you're not converting the date string to a Date object before displaying it, or if you do, adjust for the timezone offset.
This has been a common pain point with the v2 date type, and many developers have switched to using datetime with the time picker hidden as the more reliable solution. Note that you're on Studio v2 (version 2.7.1) - if you ever migrate to Studio v3, be aware that date/datetime handling has been improved, though the fundamental timezone behavior remains similar.
Show original thread6 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.