Timed banner ( date code is giving me the wrong format)

Timed banner ( date code is giving me the wrong format)

mns-burg
Excursionist
18 0 0

I made a custom section for my stores sale banner, schedule the time when its removed or added.

However the end date keep getting displayed wrong.
It should be month/date/year hour:minute:second.
But it swishes the date and month. This only for the end_date part of the code.
Screenshot 2024-10-31 at 17.02.39.png

(above what input fields)

 

Screenshot 2024-10-31 at 17.05.21.png

(Above what is shown on the page) 

The liquid part:

{% assign start_date = section.settings.bsstart_time | date: "%m/%d/%Y %H:%M:%S" %}
{% assign end_date = section.settings.bsend_time | date: "%m/%d/%Y %H:%M:%S" %}
{% assign now_date = "now" | date: "%m/%d/%Y %H:%M:%S" %}

 

The schema part:

{
                    "type": "text",
                    "id": "bsstart_time",
                    "label": "Banner start time (optional)",
                    "info": "mm/dd/yyyy hh:mm:ss"
                },
                {
                    "type": "text",
                    "id": "bsend_time",
                    "label": "Banner end time (optional)",
                    "info": "mm/dd/yyyy hh:mm:ss"
                }
Reply 1 (1)

PaulNewton
Shopify Partner
7450 656 1562

🐲💣dates in templates may be cached, "now" is NOT a reliable source of truth to disable behavior and if utilizing frontend time 💣💣 user-side-time for validation is specifically an unreliable source of time comparison (customers local browser|OS time).

 

Use a tool like shopify-flow to change metafields, or more advanced theme settings or files, also see more advanced tools like usemechanic app https://tasks.mechanic.dev/?q=theme%20time .

 

@mns-burg Join us in sanity, use YYYY-MM-DD when dealing storing date values with the ISO-8061 format https://en.wikipedia.org/wiki/ISO_8601 

 

{% assign end_date = "2024-11-01" | date: "%m/%d/%Y" %}

 

 

BYiUu

 

otherwise you need to use a unix timestamp, or dig into WHY ruby's strftime via liquid does this when the day value is smaller than 12  (12 months)

https://shopify.dev/docs/api/liquid/filters/date 

 

If using the shopify-cli is has a liquid theme console for testing logic

https://shopify.dev/changelog/liquid-console-test-and-evaluate-liquid-snippets-quickly-using-shopify... 

https://shopify.dev/docs/api/shopify-cli/theme/theme-console

 

Maintenance Nits:  Unless using locale files label the input format AND make it clear what the expected output format is too;

Namespace fully and clearly avoiding any ambiguity for future you or other devs. 

section.settings.bsend_time should be section.settings.banner_sale_end_time  etc. it's not the 1960's needing to save 10 characters , and s + end infers "send" but nothing is being sent.

 

 

Contact [email protected] for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org