Articles on: Developers

FAQ - Formatting dates with Ruby STRF

Answer



We store our dates using a raw integer value, such as "1569340710". Here is a demo of how you can convert this into a human-readable date.

Liquid Date Filter



We'll use the Liquid "date" filter to format our dates, alongside Ruby's directives to achieve any format you'd like.

Read more about the Date Filter on PlatformOS' Documentation


Format Directives



Here's a short list of some of the most useful directives when formatting dates:

%Y - The full year (including century).
%B - The full month name
%A - The full weekday name
%m - The month of the year (zero-padded)
%d - The date of the month

There are many more of these to your disposal, see the full list on Ruby's Documentation

Examples

Month-Day-Year would look like so:

{{this['release_date'] | date: "%m %d %Y"}}

Day-Month-Year (with full Month name) would be:

{{this['release_date'] | date: "%d %B %Y"}}

Month-Day-Year, separated by characters (for this example I've added forward slashes):

{{this['release_date'] | date: "%d/%B/%Y"}}

Updated on: 18/10/2021

Was this article helpful?

Share your feedback

Cancel

Thank you!