[Shopify]Liquidで日付出力する際のフォーマット まとめ一覧

[Shopify]Liquidで日付出力する際のフォーマット まとめ一覧

This is a summary of the list of formats for date output in Liquid on the Shopify store.

The date output can be used mainly for the date of publication of an article, but whether to output "2021-09-01" or "2021-09-01", we will introduce the Liquid format and how to output the date.

I hope you will find this information useful when outputting dates in the Shopify store, as it can be used anywhere!

Formatting Basics for Date Output in Shopify

The first step is to introduce the basic method of outputting dates. For example, to display the publication date of a blog post, use Liquid as shown below.

{% article.published_date | date: "%Y-%m-%d" %}

Then

%Y = year (4 digit number)
%m = month (2 digit number)
%d = day (2 digit number

)

Therefore, the output will look something like "2021-09-01".

By the way, to output the current time, use

{% "now" | date: "%Y-%m-%d" %}

The date of the day will be output by writing Liquid like the following.

List of Date Formats Available in Liquid (Dates)

Now that you understand basic date output, let's quickly summarize the list of formats that can be used with Liquid.

Weekday

%a English day of the week (Mon~Sun format)
%A English day of the week (Monday~Sunday format)
%w Numeric day of the week (0~6) 0 is Sunday

Day

%d Numeric date (01~31 format)
%e Numeric date (1~31 format) without leading 0
%j Number of days throughout the year (001~366)

Month

%b English month (Jan~Dec format)
%B English month (January~December format)
%m Numeric month (01~12 format)
%e Numeric month (1~12 format) without leading 0

Year

%Y Numeric year (4 digits, e.g., 2021)
%y Numeric year (2 digits such as 21)

List of Date Formats Available in Liquid (Time)

Next, we will add a note on time formats that may be used occasionally.

Hour

%H 24-hour notation (00~23)
%I In 12 hours (00~12) English capital I i
%l Notation in 12 hours (1~12) English lower case l el No zero

Minute

%M Minutes (00~59)

Seconds

%S Seconds (00~60)
%s Seconds (infinite?) Convert all dates, etc., to seconds and fix.
Useful for date comparisons.

[Shopify] How to get and compare dates in Liquid

Other

%P AM or PM ("am" or "pm")
%p AM or PM ("AM" or "PM")
%Z Corresponding time zone (e.g., UTC)

Extra How to convert days of the week to Japanese in Liquid

As an added bonus, you can also use Liquid to quickly correct an English date to the Japanese day of the week.

It will look something like this.

{% assign japaneseDate = article.published_date | date: %Y-%m-%d(%a)
%}{% assign japaneseDate = japaneseDate | replace: "Sun", "day" | replace: "Mon", " Mon" | replace: "Tue", "Tue" | replace: "Wed", "Wed" | replace: "Thu", "Thu" | replace: "Fri", "Fri" | replace: "Sat", "Sat" %}


and then

{{japaneseDate}}

the contents in parentheses should be "Sun,Mon,Tue,Wed,Thu,Fri,Sat".

List of formats for date output in [Shopify]Liquid Summary

This is how to manipulate date formats using Liquid on the Shopify store.

We have also written another article on how to compare two dates, if you would like to read it.

[Shopify] How to Get and Compare Dates with Liquid

I couldn't find a place where Liquid's date format is summarized, so I took this opportunity to put it together. I hope it will be helpful.

Well, thank you for reading to the end today! Have a great day!

Contact form

新規ストア構築、開発などのお仕事の依頼・無料相談はこちら