We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

How can I add 30 days to a date variable in Liquid?

Solved

How can I add 30 days to a date variable in Liquid?

Cwilliams44
Shopify Partner
7 0 2

Hello! 

 

I am trying to create a section on our site that displays when an item was prepared, and also references an expiration date, which is 30 days later. 

How exactly could this be done? 
So far I have the following: 

...

 <span>Prepared: {{ created_at | date: "%B %d, %Y" }}</span>

...

Which outputs the date in the format February 22, 2022 (for example)

How can I easily make another line that says Expires: and adds 30 days to the above date? 

 

I appreciate any assistance 🙂 

Thanks

Cloud City Drones ~ Operations Manager
Accepted Solution (1)

shadowsfall118
Shopify Partner
126 13 45

This is an accepted solution.

Take a look at this:

https://www.huratips.com/tech-tips/how-to-add-days-to-date-in-shopify-liquid.html

 

{% assign date = '2015-04-20' | date: '%s' %}
{% assign seconds = 5 | times: 24 | times: 60 | times: 60 %}
{{ date | date: "%s" | plus: seconds | date: "%Y-%m-%d" }}

 

View solution in original post

Replies 2 (2)

shadowsfall118
Shopify Partner
126 13 45

This is an accepted solution.

Take a look at this:

https://www.huratips.com/tech-tips/how-to-add-days-to-date-in-shopify-liquid.html

 

{% assign date = '2015-04-20' | date: '%s' %}
{% assign seconds = 5 | times: 24 | times: 60 | times: 60 %}
{{ date | date: "%s" | plus: seconds | date: "%Y-%m-%d" }}

 

Cwilliams44
Shopify Partner
7 0 2

Thank you very much! 

 

That worked perfect. 

for the assign date I just put {% assign date = created_at %} and it worked flawless. 

Cloud City Drones ~ Operations Manager