Liquid - get last day of the month using a date

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

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

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’

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