Liquid - get last day of the month using a date

Liquid - get last day of the month using a date

FBG_1211
Visitor
2 0 0

Hi to all

 

for my customer requirement I need to get the last day of the month starting from a given date

For example : I have 

date = '2027-11-01' 

I need to get endOfMonth='2027-11-30'

 

Any idea on how to get that result using liquid ?

 

Thanks

Replies 3 (3)

Small_Task_Help
Shopify Partner
489 15 34

Hi,

 

Converting the given date to a Liquid date object and then using the date filter to get the last day of the month.

{% assign date = '2027-11-01' | date: "%Y-%m-%d" %}
{% assign endOfMonth = date | date: "%Y-%m-%d" | date_add: '1m' | date: "%Y-%m-01" | date_subtract: '1d' %}

End of Month: {{ endOfMonth }}
Click here to Contact and Get Shopify Store Help
We are Shopify Experts   from Ecommerce Small Task Company.
FBG_1211
Visitor
2 0 0

Hello

Thanks but I got an error => Liquid error: undefined filter date_add

In some use case my date can be for example '2027-11-16' and I need to get from that date '2027-11-30'

Small_Task_Help
Shopify Partner
489 15 34

Need to check from our end. If you want you can contact us (details given at signature)

Click here to Contact and Get Shopify Store Help
We are Shopify Experts   from Ecommerce Small Task Company.