How to hide the timestamp next to the date on a Sanity blog post

15 replies
Last updated: Apr 26, 2023
Hi everyone, please help. Does anyone know how to hide the timestamp next to date on sanity blog post? We prefer to just show the date.
You've to wrap the date inside toLocaleDateString()
Hi User, thanks for responding. Where can I see this code toLocaleDateString()?
Hi robin, thanks for responding. Just want to ask this error just happened today after publishing a blog from sanity studio. Is this something I can modify on the schema?
Do your schema have a custom date field?
That's our schema for date field
You can do that on frontend. There are many libraries like " moment" to format datetime.. but if u wanna do that here in sanity schema, you can format date and time here { title: 'Launch Scheduled At',
name: 'launchAt',
type: 'datetime',
options: {
dateFormat: 'YYYY-MM-DD',
timeFormat: 'HH:mm',
timeStep: 15,
calendarTodayLabel: 'Today'
}
}, You can see thier docs for more, but you can do that on frontend just as easily
By the way, Sanity itself adds a _createdAt and _updatedAt property when you create a document.
That's correct, as you can see on the previous blog post, it is showing correct format, however when we published today's blog, it is showing date and time stamp. And we are unable to share the link to our social media site as well because of the date showing 2023-04-25T08:57:00:000Z
I'm new to Sanity and Nextjs also, User & User. Appreciate your help.
I will try to modify the blog,js schema to below:title: 'Launch Scheduled At',
name: 'launchAt',
type: 'datetime',
options: {
dateFormat: 'YYYY-MM-DD',
timeFormat: 'HH:mm',
timeStep: 15,
calendarTodayLabel: 'Today'
}
}
Do you really need a custom date field? Or you just want show to date when the post was created
Just the date (Ex. 2023-04-18) - as usually the studio function until today's issue
So you don't need a custom date field in your schema. Just add __createdAt inside your groq query. Afterwards, you can wrap it like new Date(__createdAt).toLocaleDateString() on the front end.
*[_type=="blogPosts"]{ _id, _createdAt, title, } like this

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?