Shopify Liquid show content based on dates

Solution 1:

From the Spotify liquid documentation, you can create a conditional code path using the code snippet below:

{% assign start = "2022-01-02" | date: '%s' %}
{% assign end = "2022-02-14" | date: '%s' %}
{% assign today = "now" | date: '%s' %}
{% if  start <= today and today <= end %}
    <h2>Show banner</h2>
{% endif %}

This code will only show the banner within the specified timeframes. You can try it out on the Liquid editor here: https://liquidjs.com/playground.html