All Collections
Website Builder
Blog
Website Builder: How to Change the Blog Post Date Format
Website Builder: How to Change the Blog Post Date Format

Changing the date format in a blog post with Hostinger Website Builder

Updated over a week ago

If you use Hostinger Website Builder to create a blog and want to change the date format for all of your blog posts, follow the steps below 👇

Copy the Code

<script>
function formatDate(date) {
let d = new Date(date.innerText),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;
return [year, month, day + " "].join('/');
}
setInterval(() => {
if (document.contains(document.querySelector('.block-blog-list')) && document.querySelector('.block-blog-list-item:last-of-type .blog-list-item-meta__subtitle span:first-of-type').innerHTML.at(-1) !== ' ') {
let randomPosts = document.querySelectorAll('.block-blog-list-item');
randomPosts.forEach(post => {
post.querySelector('.blog-list-item-meta__subtitle span:first-of-type').innerText = formatDate(post.querySelector('.blog-list-item-meta__subtitle span:first-of-type'));
})
}
if (document.contains(document.querySelector('.block-blog-header')) && document.querySelector('.blog-list-item-meta__subtitle span:first-of-type').innerHTML.at(-1) !== ' ') {
document.querySelector('.blog-list-item-meta__subtitle span:first-of-type').innerText = formatDate(document.querySelector('.blog-list-item-meta__subtitle span:first-of-type'));
}
}, 500);
</script>

Customize the Code

Depending on your preferred date format, change the arrangement of the values here:

return [year, month, day + " "].join('/');

The example above would return the date in the following format: yyyy/mm/dd 😊

Paste the Code

Within the builder, go to your website's SettingsIntegrations, and paste the code in the Custom code field. Then, save the changes and update your website.

The change will be visible in the preview mode and online; it's not visible in the editor.

Did this answer your question?