Ad

If Statement Based Off DATETIME In Shopify Header.liquid

- 1 answer

I am trying to add an if-then statement based off a date and time to my header.liquid.

I understand PHP and Javascript but am new to liquid and what shopify will allow.

Basically trying to display an image only during a specific date and time:

If datetime > 2019-09-06 00:00:00 PST AND < 2019-09-09 00:00:00 PST 
THEN {show image}

(Show image from 9/6 PST thru 9/9 PST)

Ad

Answer

Best way is to use the epoch time tag %s

On Shopify you can convert any date to epoch using the above {{ some_datetime_variable | %s }} and for current time it'd be {{ "now" | %s }}

More details - Dates in liquid

Ad
source: stackoverflow.com
Ad