Personalized checkout and custom promotions with Shopify Scripts
Hello! I want to display the days between a set date from section settings to today, and the assign function is not reading the id, would appriciate the help!
{%- assign dateStart = section.settings.date_started | date: '%s' -%}
{%- assign nowTimestamp = 'now' | date: '%s' -%}
{%- assign diffSeconds = nowTimestamp | minus: dateStart -%}
{%- assign diffDays = diffSeconds | divaded_by: 3600 | divided_by: 24 -%}
AND THEN I TRY TO DISPLAY IT
@Maria80 I think the following Code was your basis
{% assign dateStart = product.created_at | date: '%s' %}
{% assign nowTimestamp = 'now' | date: '%s' %}
{% comment %} difference in seconds {% endcomment %}
{% assign diffSeconds = nowTimestamp | minus: dateStart %}
{% comment %} difference in days {% endcomment %}
{% assign diffDays = diffSeconds | divided_by: 3600 | divided_by: 24 %}
<p>difference in days = {{ diffDays }}</p>
In your Code you have a few minor typos (e.g., "divaded_by" -> "divided_by") and in the container you are referencing the dateStart value and not the diffDays value. Furthermore, you inserted a translation-key filter to {{ dateStart | t }}. You can simply write {{ diffDays }}
{%- assign dateStart = section.settings.date_started | date: '%s' -%}
{%- assign nowTimestamp = 'now' | date: '%s' -%}
{%- assign diffSeconds = nowTimestamp | minus: dateStart -%}
{%- assign diffDays = diffSeconds | divided_by: 3600 | divided_by: 24 -%}
AND THEN I TRY TO DISPLAY IT
<div id="day-container" class="day-count-text">{{ diffDays }}</div>
I am not 100% sure if this will work, but from the looks this should do the job.
Hey! Thank you for your quick response, I fixed all the issues you've mention, but now I get only 0 instead of days, do you know what could have caused that?
What kind of Input are you using?
Since there is no date input in the schema of a section, I assume you are using a number?
You can check the Input options here:
https://shopify.dev/themes/architecture/settings/input-settings
I use text input 🙂 and I wrote the date like this 12/10/2022
I inserted" | t " next to the id, now it is readable by the liquid, but it shows me a wrong number 😞
@Maria80 unfortunately, Shopify will not recognize that as a date.
What is the general idea/goal behind this code? Do you want to add a countdown-timer?
Oh okay! so the goal is to calculate when someone started a challenge, so if they started on 01/12/2022, I would like it to display "D12". and then calculate it until it's day 185, then there is gonna be an icon with a check.
Where do you want to display this information?
On the Homepage or on product page?
It is a seperate page called memebers, the section you saw with socials and a text from people who are doing the challenge 🙂
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025