Forum Discussion
Liquid use case: Monday of previous week?
Hi! Absolute beginner here, with a rather specific use case query: can I use Liquid to populated an email with the date of the Monday of the previous calendar week, rendered as [number] [month], e.g. 2 January?
Contextual example would be an email that says "On the week starting [dynamic date], this happened."
3 Replies
- NirnayMentor
Hey HeatherPLI .
Try below{% comment %}Get current date in UTC{% endcomment %} {% assign today_utc = 'now' | date: '%s' | plus: 0 %} {% comment %}Get current day of week - Wednesday = 3{% endcomment %} {% assign current_day_of_week = 'now' | date: '%w' | plus: 0 %} {% comment %}Days since this week's Monday: 3 - 1 = 2{% endcomment %} {% assign days_since_monday = current_day_of_week | minus: 1 %} {% comment %}This week's Monday would be 2 days ago (Feb 10){% endcomment %} {% comment %}Previous week's Monday: 2 + 7 = 9 days ago (should be Feb 3){% endcomment %} {% assign days_to_previous_monday = days_since_monday | plus: 7 %} {% comment %}Convert to seconds{% endcomment %} {% assign seconds_to_subtract = days_to_previous_monday | times: 86400 %} {% comment %}Subtract to get previous Monday{% endcomment %} {% assign previous_monday_timestamp = today_utc | minus: seconds_to_subtract %} {% comment %}Output{% endcomment %} On the week starting {{previous_monday_timestamp | date: '%-d %B'}}, this happenedTo test this, try manipulating 'now' in today_utc and current_day_of_week variables to some random date in the following format '2021-01-01' and add - %A in the output(last line) so you see the day to confirm it is always Monday previous week.
Hope this helps!- Manoj__Visionary
Hello HeatherPLI if you are customers are in different time zone then you add time zone operator to get dates in their timezones
eg:
For a Specific timezone
{% assign today_utc = 'now' | time_zone: 'Australia/Sydney' | date: '%s' | plus: 0 %}For user based timezone
{% assign today_utc = 'now' | time_zone: '{{${time_zone}}}' | date: '%s' | plus: 0 %}- NirnayMentor
Hi Manoj__
For this specific use case, the timezone shouldn’t make a difference. The calendar date for last Monday is the same globally, whether you’re in Sydney, New York, or London, last calendar week’s Monday (February 2, 2026) remains the same date everywhere. Since we’re referencing a fixed calendar date rather than performing a time-specific calculation, using UTC will still return the correct Monday.That said, there’s certainly no downside to including it. 🙂
Related Content
- 1 year ago