Sanity date field showing day before selected date

6 replies
Last updated: Apr 6, 2021
Hey all~A little strange thing... I am using the snaity date schema type to set the date for one of my documents... When I type it a date (yyyy-mm-dd) or use the calendar UI date picker... it always sets it to the day before. If i type or select 2021-03-09 then the date showing on my screen in the field would be 2021-03-08? Strange... here are my sanity versions that I am using

@sanity/cli             2.7.1 (up to date)
@sanity/base            2.7.1 (up to date)
@sanity/color-input     2.2.6 (up to date)
@sanity/components      2.2.6 (up to date)
@sanity/core            2.7.1 (up to date)
@sanity/dashboard       2.7.0 (up to date)
@sanity/default-layout  2.7.1 (up to date)
@sanity/default-login   2.7.0 (up to date)
@sanity/desk-tool       2.7.1 (up to date)
@sanity/vision          2.7.0 (up to date)
AI Update

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 thread
6 replies
Here is an image of the studio showing the date picker
You think this is a timezone issue?
maybe... i'm in the EDT i know that used to have to adjust it when i get the date out of sanity due to the time difference...
Pretty sure they updated the date picker the other day. If it's a bug they now ask people to submit an issue to the GitHub repo.
will do thanks!
Thanks for reporting
user R
, this should be fixed in the latest release

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.

Was this answer helpful?