🔮 Sanity Create is here. Writing is reinvented. Try now, no developer setup

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.
Apr 26, 2023, 6:52 AM
You've to wrap the date inside toLocaleDateString()
Apr 26, 2023, 8:13 AM
Hi User, thanks for responding. Where can I see this code toLocaleDateString()?
Apr 26, 2023, 9:04 AM
Apr 26, 2023, 9:11 AM
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?
Apr 26, 2023, 9:19 AM
Do your schema have a custom date field?
Apr 26, 2023, 11:09 AM
That's our schema for date field
Apr 26, 2023, 11:11 AM
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
Apr 26, 2023, 11:14 AM
By the way, Sanity itself adds a _createdAt and _updatedAt property when you create a document.
Apr 26, 2023, 11:18 AM
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
Apr 26, 2023, 11:22 AM
I'm new to Sanity and Nextjs also, User & User. Appreciate your help.
Apr 26, 2023, 11:22 AM
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'
}
}
Apr 26, 2023, 11:23 AM
Do you really need a custom date field? Or you just want show to date when the post was created
Apr 26, 2023, 11:24 AM
Just the date (Ex. 2023-04-18) - as usually the studio function until today's issue
Apr 26, 2023, 11:25 AM
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.
Apr 26, 2023, 11:27 AM
*[_type=="blogPosts"]{ _id, _createdAt, title, } like this
Apr 26, 2023, 11:29 AM

Sanity– build remarkable experiences at scale

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

Was this answer helpful?