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
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 %}
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.
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.