Log in Sign up

Formatting a custom date field?

Hello,

I have a custom date field that looks like this: update: 2015-05-12. I've seen there are ways to format dates for built-in fields. Is there a way to do so for custom fields?

Alex


9 hours ago, 3 replies   developers   dates   Edit question

No, there are no general purpose date parsing and display functions, only those for displaying the post's publish date, date updated, date created, etc. I would recommend either typing in the custom metadata exactly as you want the date to display, or loading in the date with javascript in your template's script.js file and formatting it there.

If you tell me a little more about what you're trying to achieve, I'd be happy to help work out a way

Answered a day ago · Edit answer

I wasn't trying to be obscure. I have an update field that has a date in ISO (say, 2015-05-12 and I want it to output like this: 12 May 2025.

I added the following to script.js which does the trick:

// Convert the "#update-metadata" field, if it exists, to a prettier format
const updateMetadata = document.getElementById('update-metadata');
const date = new Date(updateMetadata.textContent.trim());
updateMetadata.textContent = `${date.getDate()} ${date.toLocaleString('en-US', {month: 'long'})} ${date.getFullYear()}`;

Alex

Answered 20 hours ago · Edit answer

If you just want to display the date the file was updated, you can do this:

{{#formatUpdated}}MMMM Do, YYYY{{/formatUpdated}}

Use any of the date tokens

Answered 9 hours ago · Edit answer

Newsletter
Get updates on Blot’s latest features and changes. Delivered every three months.