Discussion about date field changes and using emojis as icons in Sanity.io

7 replies
Last updated: Apr 2, 2021
Hey, are there any changes to the date field? I have the following:
type: 'date',

options: {

dateFormat: 'YYYY-MM',

},
however the dateFormat is not being respected and I’m getting
date:Ā "2021-04-01T07:00:00.000Z"
which is strange, because older documents have
date:Ā "2021-04"
in the front end.
Also in the subtitle i’m seeing something else:
AI Update

The issue you're experiencing isn't due to a change in how the dateFormat option works - there's actually a mismatch between what you're expecting and what's happening.

According to the official Sanity documentation for the date type, the date type should store values as date-only strings in "YYYY-MM-DD" format, not as full ISO datetime strings with time components.

The fact that you're seeing "2021-04-01T07:00:00.000Z" (with time) instead of "2021-04" or "2021-04-01" suggests you might actually be using the datetime type instead of the date type, or there's a type mismatch somewhere in your schema.

Here's what's likely happening:

The dateFormat option only controls how the date is displayed in the Studio UI - it doesn't change what gets stored in your dataset. The stored value for a date type should always be "YYYY-MM-DD" format.

Your older documents with "2021-04" are storing incomplete date strings, which isn't standard for Sanity's date type. This might have been from a custom input or a different field type.

To fix this:

  1. Double-check your schema - Make sure you're using type: 'date' and not type: 'datetime':

    {
      type: 'date',  // NOT 'datetime'
      name: 'date',
      options: {
        dateFormat: 'YYYY-MM'  // This only affects display, not storage
      }
    }
  2. If you truly need year-month only storage, you'll need to use a custom input component or store it as a string type, since the native date type will always store the full "YYYY-MM-DD" format.

  3. Check your queries/frontend - The datetime values you're seeing might be coming from a different field or being transformed somewhere in your data pipeline.

The dateFormat: 'YYYY-MM' option will make the Studio display the date as "2021-04", but the stored value will still be "2021-04-01" (with a day component defaulting to 01).

Hey there! It looks like changes to date and dateTime happened in in
v2.6.3
. Here’s an overview.
user D
How did you set up to use the emojis as the icon?
user S
In your schema, this should work:
export default {
  name: 'Example Schema',
  type: 'document',
  fields: [
    // Your schema fields
  ],
  preview: {
    select: {
      media: 'šŸ˜€'
    }
  }
}
There’s some more info in the docs ~ 1)
https://www.sanity.io/docs/previews-list-views 2) https://www.sanity.io/docs/icons-for-data-types 3) https://www.sanity.io/docs/customization
That’s awesome. I wonder if this can be used in the structure builder too using
.icon(...)
It’s mentioned here although I personally couldn’t seem to get it working the other day…
user S
check this šŸ˜›. You. can also make a file icons.js and export them all from there, you know the drill. I like this approach cuz you can add css to align them nicely.

import S from '@sanity/desk-tool/structure-builder'

import React from 'react'

import Emoji from 'a11y-react-emoji'


// Icons

const IconInformation = () => (

<Emoji style={{ fontSize: '1.5rem' }} symbol=":tophat:" />

)

const IconHome = () => <Emoji style={{ fontSize: '1.5rem' }} symbol=":house_with_garden:" />

const IconSelectedWork = () => (

<Emoji style={{ fontSize: '1.5rem' }} symbol=":star:" />

)

const IconSiteSettings = () => (

<Emoji style={{ fontSize: '1.5rem' }} symbol=":gear:" />

)

const IconClients = () => <Emoji style={{ fontSize: '1.5rem' }} symbol=":champagne:" />

const IconNavigation = () => (

<Emoji style={{ fontSize: '1.5rem' }} symbol=":compass:" />

)


const hiddenDocTypes = (listItem) =>

![

'home',

'information',

'siteSettings',

'selectedWork',

'clients',

'navigation',

].includes(listItem.getId())


export default () =>

S.list()

.title('Content')

.items([

...S.documentTypeListItems().filter(hiddenDocTypes),

S.listItem()

.title('Selected Work')

.icon(IconSelectedWork)

.child(

S.editor()

.id('selectedWork')

.schemaType('selectedWork')

.documentId('selectedWork')

),

S.divider(),

S.listItem()

.title('Navigation Content')

.icon(IconNavigation)

.child(

S.editor()

.id('navigation')

.schemaType('navigation')

.documentId('navigation')

),

S.divider(),

S.listItem()

.title('Site Settings')

.icon(IconSiteSettings)

.child(

S.editor()

.id('siteSettings')

.schemaType('siteSettings')

.documentId('siteSettings')

),

S.divider(),

S.listItem()

.title('Home')

.icon(IconHome)

.child(S.editor().id('home').schemaType('home').documentId('home')),

S.listItem()

.title('Clients')

.icon(IconClients)

.child(

S.editor().id('clients').schemaType('clients').documentId('clients')

),

S.listItem()

.title('Information')

.icon(IconInformation)

.child(

S.editor()

.id('information')

.schemaType('information')

.documentId('information')

),

])
user D
Cool!! Clients == šŸ¾ ftw!

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?