How can I adjust the Liquid date output to exclude weekends in delivery dates?

Hello experts :slightly_smiling_face:

I have a little problem with Liquid date output…
I created an output text on my product page stating when the delivery will be delivered at the latest, which is why the delivery days were stored individually for each product with metafields.

So far so good, I managed everything :slightly_smiling_face:

However, it can also happen that the delivery date shows Saturday or Sunday - but I would like to avoid that and am desperate to get the right code …
Can you help me please?

If the issue date was Saturday, it should appear: delivery day +2 days to Monday, if Sunday +1 day to Monday.

Here is my current code:

{% if product.metafields.my_fields.deliverymax != blank %}

{% assign delivery_day1 = product.metafields.my_fields.deliverymax | times: 86400 %}

{{ “now” | date: “%s” | plus: delivery_day1 | time_tag: format: ‘day_month’ }}

{% else %}
{% endif %}

Thank you & best regards
Mark

@Wabema

You will want to check to see if the date is on Saturday or Sunday and then add the appropriate amount of time to the date for adding one day or two days for the result.

Checking the day of the week can be done with “%w” where Sunday is “0”. From there you can get the day of the month and simply add 1 or 2 to it then convert that back into a date and format it however you need.

I can reply with the exact code a bit later if you would like but a good reference is the date filter reference.

I worked with the date filter quite a bit recently building out a calendar section to sell for merchants to add to their theme for selling event tickets. The good thing is that you can get the date parts and just modify them then put it back into a date like “2022-02-05” for example to grab other date details about the new date.

Hope that helps!

Hi Rob,

many thanks for your response!

I’ve tried many different options without success, I think I’ve made a serious mistake here :slightly_smiling_face:

I have coded this for a test …inconclusive…:

{% assign delivery_day1 = product.metafields.my_fields.deliverymin | times: 86400 | date: '%u' %}
{% assign today = 'now' | date: '%s' %}
{% assign single_day = 86400 %}
{% assign today_numbermin = delivery_day1 | date: '%u' | plus: 'now' %}

{% assign days_until_next1 = 8 | minus: today_numbermin | plus: product.metafields.my_fields.deliverymin  %}
{% assign days_unix1 = days_until_next1 | times: single_day  %}
{% assign days_until_next2 = 7 | minus: today_numbermin | plus: product.metafields.my_fields.deliverymin  %}
{% assign days_unix2 = days_until_next2 | times: single_day  %}

{% if  today_numbermin == 7 %}  
Min: customized1 {{ today | plus: days_unix1  | date: '%A--%Y/%m/%d' }}

{% else %}
{% endif %}
{% if  today_numbermin == 6 %}  
Min: customized2 {{ today | plus: days_unix2  | date: '%A--%Y/%m/%d' }}

{% else %}
{% endif %}
{% if  today_numbermin <= 5 %}  
Min: Standard {{ today | plus: delivery_day1 | date: '%A--%Y/%m/%d' }}

{% else %}
{% endif %}

min has the meaning of minimum, since I want to output 2 date values ​​here, in which period the delivery will come at least and up to which maximum date it can last.

thanks & have a nice day

Mark