LiquidJS Date Filters
This page provides a comprehensive set of date manipulation filters for LiquidJS templates, powered by Moment.js.
Overview
Date filters allow you to format, manipulate, and compare dates directly within your Liquid templates. All filters handle null/undefined values gracefully.
Quick Reference
| Category | Filters |
|---|---|
| Formatting | date_format, now, date_parse, day_of_week, month_name, timezone_offset |
| Arithmetic | date_add, date_subtract, date_diff |
| Boundaries | start_of, end_of |
| Relative | from_now, to_now |
| Comparison | is_before, is_after, is_same |
| Validation | is_valid_date, is_today, is_past, is_future |
Common Date Format Tokens
| Token | Description | Example |
|---|---|---|
YYYY | 4-digit year | 2024 |
YY | 2-digit year | 24 |
MMMM | Full month name | January |
MMM | Abbreviated month | Jan |
MM | 2-digit month | 01 |
M | Month | 1 |
DD | 2-digit day | 05 |
D | Day | 5 |
dddd | Full weekday | Monday |
ddd | Abbreviated weekday | Mon |
HH | 24-hour hour | 14 |
hh | 12-hour hour | 02 |
mm | Minutes | 30 |
ss | Seconds | 45 |
A | AM/PM | PM |
a | am/pm | pm |
Z | Timezone offset | +05:30 |
Formatting Filters
date_format
date_formatFormats a date using a specified format string.
Syntax
{{ date | date_format: "format" }}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
format | string | No | "YYYY-MM-DD" | Moment.js format string |
Examples
{% comment %} Basic formatting {% endcomment %}
{{ order.created_at | date_format: "MMMM D, YYYY" }}
<!-- Output: January 15, 2024 -->
{% comment %} With time {% endcomment %}
{{ order.created_at | date_format: "YYYY-MM-DD HH:mm:ss" }}
<!-- Output: 2024-01-15 14:30:00 -->
{% comment %} Friendly format {% endcomment %}
{{ order.created_at | date_format: "dddd, MMMM Do YYYY" }}
<!-- Output: Monday, January 15th 2024 -->
{% comment %} Short date {% endcomment %}
{{ order.created_at | date_format: "MM/DD/YY" }}
<!-- Output: 01/15/24 -->
{% comment %} Time only {% endcomment %}
{{ order.created_at | date_format: "h:mm A" }}
<!-- Output: 2:30 PM -->
{% comment %} ISO format (default) {% endcomment %}
{{ order.created_at | date_format }}
<!-- Output: 2024-01-15 -->
{% comment %} Null handling {% endcomment %}
{{ null | date_format: "YYYY-MM-DD" }}
<!-- Output: (empty string) -->now
nowGets the current date/time, optionally formatted.
Syntax
{{ "now" | now }}
{{ "now" | now: "format" }}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
format | string | No | ISO 8601 | Moment.js format string |
Examples
{% comment %} Current ISO timestamp {% endcomment %}
{{ "now" | now }}
<!-- Output: 2024-01-15T14:30:00.000Z -->
{% comment %} Formatted current date {% endcomment %}
{{ "now" | now: "YYYY-MM-DD" }}
<!-- Output: 2024-01-15 -->
{% comment %} Current time {% endcomment %}
{{ "now" | now: "HH:mm:ss" }}
<!-- Output: 14:30:00 -->
{% comment %} Full formatted {% endcomment %}
{{ "now" | now: "MMMM D, YYYY [at] h:mm A" }}
<!-- Output: January 15, 2024 at 2:30 PM -->
{% comment %} Use in comparisons {% endcomment %}
{% assign today = "now" | now: "YYYY-MM-DD" %}
{% if order.date == today %}
Order placed today!
{% endif %}date_parse
date_parseParses a date with a specific input format and outputs in another format.
Syntax
{{ date_string | date_parse: "inputFormat", "outputFormat" }}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
inputFormat | string | Yes | - | Format of the input date string |
outputFormat | string | No | "YYYY-MM-DD" | Desired output format |
Examples
{% comment %} Parse European date format {% endcomment %}
{{ "15/01/2024" | date_parse: "DD/MM/YYYY", "YYYY-MM-DD" }}
<!-- Output: 2024-01-15 -->
{% comment %} Parse US date format {% endcomment %}
{{ "01-15-2024" | date_parse: "MM-DD-YYYY", "MMMM D, YYYY" }}
<!-- Output: January 15, 2024 -->
{% comment %} Parse with time {% endcomment %}
{{ "15-Jan-2024 14:30" | date_parse: "DD-MMM-YYYY HH:mm", "YYYY-MM-DD HH:mm:ss" }}
<!-- Output: 2024-01-15 14:30:00 -->
{% comment %} Parse text date {% endcomment %}
{{ "January 15, 2024" | date_parse: "MMMM D, YYYY", "YYYY-MM-DD" }}
<!-- Output: 2024-01-15 -->
{% comment %} Default output format {% endcomment %}
{{ "15/01/2024" | date_parse: "DD/MM/YYYY" }}
<!-- Output: 2024-01-15 -->day_of_week
day_of_weekGets the name of the day of the week.
Syntax
{{ date | day_of_week }}
{{ date | day_of_week: "style" }}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
style | string | No | "long" | "long" for full name, "short" for abbreviated |
Examples
{% comment %} Full day name {% endcomment %}
{{ order.date | day_of_week }}
<!-- Output: Monday -->
{% comment %} Short day name {% endcomment %}
{{ order.date | day_of_week: "short" }}
<!-- Output: Mon -->
{% comment %} Use in a message {% endcomment %}
Your order was placed on {{ order.date | day_of_week }}.
<!-- Output: Your order was placed on Monday. -->
{% comment %} Conditional based on day {% endcomment %}
{% assign day = order.date | day_of_week %}
{% if day == "Saturday" or day == "Sunday" %}
Weekend order - processing may be delayed.
{% endif %}month_name
month_nameGets the name of the month.
Syntax
{{ date | month_name }}
{{ date | month_name: "style" }}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
style | string | No | "long" | "long" for full name, "short" for abbreviated |
Examples
{% comment %} Full month name {% endcomment %}
{{ order.date | month_name }}
<!-- Output: January -->
{% comment %} Short month name {% endcomment %}
{{ order.date | month_name: "short" }}
<!-- Output: Jan -->
{% comment %} Use in a header {% endcomment %}
<h2>{{ report.date | month_name }} Report</h2>
<!-- Output: <h2>January Report</h2> -->
{% comment %} Combined with year {% endcomment %}
{{ order.date | month_name }} {{ order.date | date_format: "YYYY" }}
<!-- Output: January 2024 -->timezone_offset
timezone_offsetGets the timezone offset of a date.
Syntax
{{ date | timezone_offset }}Examples
{% comment %} Get timezone offset {% endcomment %}
{{ order.date | timezone_offset }}
<!-- Output: +05:30 -->
{% comment %} Display with date {% endcomment %}
{{ order.date | date_format: "YYYY-MM-DD HH:mm" }} (UTC{{ order.date | timezone_offset }})
<!-- Output: 2024-01-15 14:30 (UTC+05:30) -->Arithmetic Filters
date_add
date_addAdds time to a date.
Syntax
{{ date | date_add: amount, "unit" }}
{{ date | date_add: amount, "unit", "format" }}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
amount | number | Yes | - | Amount to add |
unit | string | No | "days" | Time unit (see table below) |
format | string | No | ISO 8601 | Output format |
Available Units
| Unit | Aliases |
|---|---|
years | year, y |
months | month, M |
weeks | week, w |
days | day, d |
hours | hour, h |
minutes | minute, m |
seconds | second, s |
Examples
{% comment %} Add days {% endcomment %}
{{ order.date | date_add: 7, "days" }}
<!-- Output: 2024-01-22T00:00:00.000Z -->
{% comment %} Add days with format {% endcomment %}
{{ order.date | date_add: 7, "days", "YYYY-MM-DD" }}
<!-- Output: 2024-01-22 -->
{% comment %} Add months {% endcomment %}
{{ order.date | date_add: 1, "months", "MMMM D, YYYY" }}
<!-- Output: February 15, 2024 -->
{% comment %} Add hours {% endcomment %}
{{ order.date | date_add: 24, "hours", "YYYY-MM-DD HH:mm" }}
<!-- Output: 2024-01-16 00:00 -->
{% comment %} Calculate delivery date {% endcomment %}
Expected delivery: {{ order.date | date_add: 5, "days", "MMMM D" }}
<!-- Output: Expected delivery: January 20 -->
{% comment %} Add years {% endcomment %}
{{ subscription.start_date | date_add: 1, "years", "YYYY-MM-DD" }}
<!-- Output: 2025-01-15 -->
{% comment %} Calculate expiry {% endcomment %}
{% assign expiry = membership.start | date_add: 30, "days", "YYYY-MM-DD" %}
Your membership expires on {{ expiry }}.date_subtract
date_subtractSubtracts time from a date.
Syntax
{{ date | date_subtract: amount, "unit" }}
{{ date | date_subtract: amount, "unit", "format" }}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
amount | number | Yes | - | Amount to subtract |
unit | string | No | "days" | Time unit |
format | string | No | ISO 8601 | Output format |
Examples
{% comment %} Subtract days {% endcomment %}
{{ order.date | date_subtract: 7, "days", "YYYY-MM-DD" }}
<!-- Output: 2024-01-08 -->
{% comment %} Get last month {% endcomment %}
{{ "now" | now | date_subtract: 1, "months", "MMMM YYYY" }}
<!-- Output: December 2023 -->
{% comment %} Calculate past date {% endcomment %}
Order was placed {{ order.date | date_subtract: 0, "days", "D [days ago on] dddd" }}
{% comment %} Get start of billing period {% endcomment %}
{% assign billing_start = billing.end_date | date_subtract: 30, "days", "YYYY-MM-DD" %}
Billing period: {{ billing_start }} to {{ billing.end_date | date_format: "YYYY-MM-DD" }}date_diff
date_diffGets the difference between two dates.
Syntax
{{ date1 | date_diff: date2, "unit" }}
{{ date1 | date_diff: date2, "unit", precise }}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
date2 | date/string | Yes | - | The date to compare against |
unit | string | No | "days" | Unit for the difference |
precise | boolean | No | false | Return decimal value |
Examples
{% comment %} Days between dates {% endcomment %}
{{ order.end_date | date_diff: order.start_date, "days" }}
<!-- Output: 30 -->
{% comment %} Months between dates {% endcomment %}
{{ subscription.end | date_diff: subscription.start, "months" }}
<!-- Output: 12 -->
{% comment %} Precise difference {% endcomment %}
{{ project.end | date_diff: project.start, "days", true }}
<!-- Output: 30.5 -->
{% comment %} Hours between dates {% endcomment %}
{{ event.end_time | date_diff: event.start_time, "hours" }}
<!-- Output: 2 -->
{% comment %} Calculate age {% endcomment %}
{% assign age = "now" | now | date_diff: user.birthdate, "years" %}
User is {{ age }} years old.
{% comment %} Days until deadline {% endcomment %}
{% assign days_left = deadline | date_diff: "now" | now, "days" %}
{% if days_left > 0 %}
{{ days_left }} days remaining
{% else %}
Deadline passed
{% endif %}
{% comment %} Duration display {% endcomment %}
{% assign duration = booking.checkout | date_diff: booking.checkin, "days" %}
Stay duration: {{ duration }} night{% if duration != 1 %}s{% endif %}Boundary Filters
start_of
start_ofGets the start of a time period.
Syntax
{{ date | start_of: "unit" }}
{{ date | start_of: "unit", "format" }}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
unit | string | No | "day" | Time period unit |
format | string | No | ISO 8601 | Output format |
Available Units
year, quarter, month, week, isoWeek, day, hour, minute, second
Examples
{% comment %} Start of day {% endcomment %}
{{ order.date | start_of: "day", "YYYY-MM-DD HH:mm:ss" }}
<!-- Output: 2024-01-15 00:00:00 -->
{% comment %} Start of month {% endcomment %}
{{ order.date | start_of: "month", "YYYY-MM-DD" }}
<!-- Output: 2024-01-01 -->
{% comment %} Start of week {% endcomment %}
{{ order.date | start_of: "week", "YYYY-MM-DD" }}
<!-- Output: 2024-01-14 (Sunday) -->
{% comment %} Start of ISO week (Monday) {% endcomment %}
{{ order.date | start_of: "isoWeek", "YYYY-MM-DD" }}
<!-- Output: 2024-01-15 -->
{% comment %} Start of year {% endcomment %}
{{ order.date | start_of: "year", "MMMM D, YYYY" }}
<!-- Output: January 1, 2024 -->
{% comment %} Start of quarter {% endcomment %}
{{ order.date | start_of: "quarter", "YYYY-MM-DD" }}
<!-- Output: 2024-01-01 -->
{% comment %} Use for date range {% endcomment %}
{% assign month_start = report.date | start_of: "month", "YYYY-MM-DD" %}
{% assign month_end = report.date | end_of: "month", "YYYY-MM-DD" %}
Report for {{ month_start }} to {{ month_end }}end_of
end_ofGets the end of a time period.
Syntax
{{ date | end_of: "unit" }}
{{ date | end_of: "unit", "format" }}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
unit | string | No | "day" | Time period unit |
format | string | No | ISO 8601 | Output format |
Examples
{% comment %} End of day {% endcomment %}
{{ order.date | end_of: "day", "YYYY-MM-DD HH:mm:ss" }}
<!-- Output: 2024-01-15 23:59:59 -->
{% comment %} End of month {% endcomment %}
{{ order.date | end_of: "month", "YYYY-MM-DD" }}
<!-- Output: 2024-01-31 -->
{% comment %} End of year {% endcomment %}
{{ order.date | end_of: "year", "MMMM D, YYYY" }}
<!-- Output: December 31, 2024 -->
{% comment %} End of week {% endcomment %}
{{ order.date | end_of: "week", "YYYY-MM-DD" }}
<!-- Output: 2024-01-20 (Saturday) -->
{% comment %} Trial expiration {% endcomment %}
{% assign trial_end = user.signup_date | date_add: 14, "days" | end_of: "day", "MMMM D, YYYY [at] 11:59 PM" %}
Your trial expires on {{ trial_end }}.Relative Time Filters
from_now
from_nowGets a human-readable relative time from now.
Syntax
{{ date | from_now }}
{{ date | from_now: withoutSuffix }}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
withoutSuffix | boolean | No | false | Remove "ago" / "in" suffix |
Examples
{% comment %} Basic usage {% endcomment %}
{{ order.date | from_now }}
<!-- Output: 2 days ago -->
<!-- Output: in 3 hours -->
<!-- Output: a few seconds ago -->
{% comment %} Without suffix {% endcomment %}
{{ order.date | from_now: true }}
<!-- Output: 2 days -->
{% comment %} Use in context {% endcomment %}
Order placed {{ order.date | from_now }}
<!-- Output: Order placed 2 days ago -->
{% comment %} Last updated {% endcomment %}
Last updated: {{ article.updated_at | from_now }}
<!-- Output: Last updated: 5 minutes ago -->
{% comment %} Various examples of output {% endcomment %}
<!-- seconds ago -->
<!-- a minute ago -->
<!-- 5 minutes ago -->
<!-- an hour ago -->
<!-- 3 hours ago -->
<!-- a day ago -->
<!-- 5 days ago -->
<!-- a month ago -->
<!-- 3 months ago -->
<!-- a year ago -->
<!-- 2 years ago -->to_now
to_nowGets a human-readable relative time to now (inverse of from_now).
Syntax
{{ date | to_now }}
{{ date | to_now: withoutSuffix }}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
withoutSuffix | boolean | No | false | Remove "ago" / "in" suffix |
Examples
{% comment %} Basic usage {% endcomment %}
{{ future_date | to_now }}
<!-- Output: in 5 days -->
{% comment %} Without suffix {% endcomment %}
{{ future_date | to_now: true }}
<!-- Output: 5 days -->
{% comment %} Event countdown {% endcomment %}
Event starts {{ event.start_date | to_now }}
<!-- Output: Event starts in 3 days -->Comparison Filters
is_before
is_beforeChecks if a date is before another date.
Syntax
{{ date | is_before: compareDate }}
{{ date | is_before: compareDate, "unit" }}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
compareDate | date/string | Yes | - | Date to compare against |
unit | string | No | - | Granularity for comparison |
Examples
{% comment %} Basic comparison {% endcomment %}
{{ order.date | is_before: order.deadline }}
<!-- Output: true or false -->
{% comment %} Use in conditional {% endcomment %}
{% if order.date | is_before: order.deadline %}
Order placed before deadline ✓
{% else %}
Order placed after deadline
{% endif %}
{% comment %} Compare with unit granularity {% endcomment %}
{% if order.date | is_before: cutoff_date, "day" %}
Eligible for promotion
{% endif %}
{% comment %} Compare with current date {% endcomment %}
{% assign now = "now" | now %}
{% if subscription.end_date | is_before: now %}
Subscription has expired
{% endif %}is_after
is_afterChecks if a date is after another date.
Syntax
{{ date | is_after: compareDate }}
{{ date | is_after: compareDate, "unit" }}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
compareDate | date/string | Yes | - | Date to compare against |
unit | string | No | - | Granularity for comparison |
Examples
{% comment %} Basic comparison {% endcomment %}
{{ order.ship_date | is_after: order.order_date }}
<!-- Output: true -->
{% comment %} Use in conditional {% endcomment %}
{% if payment.date | is_after: invoice.due_date %}
<span class="late">Late payment</span>
{% endif %}
{% comment %} Check if future date {% endcomment %}
{% assign now = "now" | now %}
{% if event.date | is_after: now %}
<button>Register Now</button>
{% else %}
<span>Event has passed</span>
{% endif %}is_same
is_sameChecks if a date is the same as another date.
Syntax
{{ date | is_same: compareDate, "unit" }}Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
compareDate | date/string | Yes | - | Date to compare against |
unit | string | No | "day" | Granularity for comparison |
Examples
{% comment %} Same day {% endcomment %}
{{ order.date | is_same: delivery.date, "day" }}
<!-- Output: true or false -->
{% comment %} Same month {% endcomment %}
{% if report.date | is_same: comparison.date, "month" %}
Same month comparison
{% endif %}
{% comment %} Same year {% endcomment %}
{% if order.date | is_same: "2024-01-01", "year" %}
2024 order
{% endif %}
{% comment %} Check for same week {% endcomment %}
{% assign now = "now" | now %}
{% if order.date | is_same: now, "week" %}
Ordered this week
{% endif %}
{% comment %} Exact match (to the millisecond) {% endcomment %}
{% if timestamp1 | is_same: timestamp2, "millisecond" %}
Exact match
{% endif %}Validation Filters
is_valid_date
is_valid_dateChecks if a value is a valid date.
Syntax
{{ value | is_valid_date }}Examples
{% comment %} Valid date {% endcomment %}
{{ "2024-01-15" | is_valid_date }}
<!-- Output: true -->
{% comment %} Invalid date {% endcomment %}
{{ "not-a-date" | is_valid_date }}
<!-- Output: false -->
{% comment %} Invalid date (Feb 30) {% endcomment %}
{{ "2024-02-30" | is_valid_date }}
<!-- Output: false -->
{% comment %} Use in conditional {% endcomment %}
{% if user_input | is_valid_date %}
{{ user_input | date_format: "MMMM D, YYYY" }}
{% else %}
Invalid date provided
{% endif %}
{% comment %} Validate before processing {% endcomment %}
{% if order.custom_date | is_valid_date %}
{% assign formatted = order.custom_date | date_format: "YYYY-MM-DD" %}
{% else %}
{% assign formatted = "N/A" %}
{% endif %}is_today
is_todayChecks if a date is today.
Syntax
{{ date | is_today }}Examples
{% comment %} Basic check {% endcomment %}
{{ order.date | is_today }}
<!-- Output: true or false -->
{% comment %} Use in conditional {% endcomment %}
{% if order.date | is_today %}
<span class="badge">Today</span>
{% endif %}
{% comment %} Highlight today's orders {% endcomment %}
{% for order in orders %}
<div class="order {% if order.date | is_today %}today{% endif %}">
{{ order.id }}
</div>
{% endfor %}
{% comment %} Today's special message {% endcomment %}
{% if event.date | is_today %}
🎉 This event is happening today!
{% endif %}is_past
is_pastChecks if a date is in the past.
Syntax
{{ date | is_past }}Examples
{% comment %} Basic check {% endcomment %}
{{ order.deadline | is_past }}
<!-- Output: true or false -->
{% comment %} Expired check {% endcomment %}
{% if coupon.expiry_date | is_past %}
<span class="expired">This coupon has expired</span>
{% else %}
<button>Apply Coupon</button>
{% endif %}
{% comment %} Past event {% endcomment %}
{% if event.date | is_past %}
<span class="status">Event completed</span>
{% else %}
<span class="status">Upcoming</span>
{% endif %}
{% comment %} Overdue indicator {% endcomment %}
{% if invoice.due_date | is_past %}
<span class="overdue">OVERDUE</span>
{% endif %}is_future
is_futureChecks if a date is in the future.
Syntax
{{ date | is_future }}Examples
{% comment %} Basic check {% endcomment %}
{{ event.date | is_future }}
<!-- Output: true or false -->
{% comment %} Show registration for future events {% endcomment %}
{% if event.date | is_future %}
<button>Register Now</button>
{% else %}
<span>Registration closed</span>
{% endif %}
{% comment %} Upcoming indicator {% endcomment %}
{% if release.date | is_future %}
<span class="coming-soon">Coming {{ release.date | from_now }}</span>
{% endif %}
{% comment %} Pre-order available {% endcomment %}
{% if product.release_date | is_future %}
<button>Pre-order</button>
<p>Available {{ product.release_date | date_format: "MMMM D, YYYY" }}</p>
{% else %}
<button>Buy Now</button>
{% endif %}Combined Examples
Order Status Template
{% assign now = "now" | now %}
<div class="order">
<h2>Order #{{ order.id }}</h2>
<p>
Ordered: {{ order.date | date_format: "MMMM D, YYYY" }}
({{ order.date | from_now }})
</p>
{% if order.date | is_today %}
<span class="badge new">New Order</span>
{% endif %}
{% assign delivery_date = order.date | date_add: 5, "days" %}
<p>
Expected Delivery: {{ delivery_date | date_format: "MMMM D, YYYY" }}
{% if delivery_date | is_future %}
({{ delivery_date | from_now }})
{% else %}
(Delivered)
{% endif %}
</p>
</div>Subscription Management
<div class="subscription">
<h3>{{ plan.name }}</h3>
<p>Start Date: {{ subscription.start_date | date_format: "MMMM D, YYYY" }}</p>
<p>End Date: {{ subscription.end_date | date_format: "MMMM D, YYYY" }}</p>
{% assign duration = subscription.end_date | date_diff: subscription.start_date, "months" %}
<p>Duration: {{ duration }} months</p>
{% if subscription.end_date | is_past %}
<span class="status expired">Expired</span>
<p>Expired {{ subscription.end_date | from_now }}</p>
{% elsif subscription.end_date | is_future %}
{% assign days_left = subscription.end_date | date_diff: now, "days" %}
{% if days_left <= 7 %}
<span class="status warning">Expiring Soon</span>
<p>{{ days_left }} days remaining</p>
{% else %}
<span class="status active">Active</span>
<p>Expires {{ subscription.end_date | from_now }}</p>
{% endif %}
{% endif %}
</div>Event Calendar
{% for event in events %}
<div class="event">
<h3>{{ event.name }}</h3>
<p class="date">
{{ event.date | day_of_week }},
{{ event.date | month_name: "short" }}
{{ event.date | date_format: "D, YYYY" }}
</p>
<p class="time">
{{ event.start_time | date_format: "h:mm A" }} -
{{ event.end_time | date_format: "h:mm A" }}
</p>
{% if event.date | is_today %}
<span class="badge today">Today!</span>
{% elsif event.date | is_future %}
<span class="badge upcoming">{{ event.date | from_now }}</span>
{% else %}
<span class="badge past">Past Event</span>
{% endif %}
</div>
{% endfor %}Date Range Report
{% assign report_start = report.date | start_of: "month", "YYYY-MM-DD" %}
{% assign report_end = report.date | end_of: "month", "YYYY-MM-DD" %}
{% assign last_month_start = report.date | date_subtract: 1, "months" | start_of: "month", "YYYY-MM-DD" %}
{% assign last_month_end = report.date | date_subtract: 1, "months" | end_of: "month", "YYYY-MM-DD" %}
<h1>{{ report.date | month_name }} {{ report.date | date_format: "YYYY" }} Report</h1>
<p>Period: {{ report_start | date_format: "MMM D" }} - {{ report_end | date_format: "MMM D, YYYY" }}</p>
<p>Previous Period: {{ last_month_start | date_format: "MMM D" }} - {{ last_month_end | date_format: "MMM D, YYYY" }}</p>
<p>Report Generated: {{ "now" | now: "MMMM D, YYYY [at] h:mm A" }}</p>Error Handling
All date filters handle null and undefined values gracefully:
| Filter | Null/Undefined Input | Invalid Date Input |
|---|---|---|
date_format | Returns "" | Returns "Invalid date" |
now | Returns current date | Returns current date |
date_add | Returns "" | May return invalid |
date_subtract | Returns "" | May return invalid |
date_diff | Returns 0 | Returns NaN |
is_before | Returns false | Returns false |
is_after | Returns false | Returns false |
is_same | Returns false | Returns false |
is_valid_date | Returns false | Returns false |
is_today | Returns false | Returns false |
is_past | Returns false | Returns false |
is_future | Returns false | Returns false |
from_now | Returns "" | Returns "Invalid date" |
to_now | Returns "" | Returns "Invalid date" |
start_of | Returns "" | May return invalid |
end_of | Returns "" | May return invalid |
day_of_week | Returns "" | Returns "Invalid date" |
month_name | Returns "" | Returns "Invalid date" |
date_parse | Returns "" | Returns "Invalid date" |
Safe Usage Pattern
{% if user_date | is_valid_date %}
{{ user_date | date_format: "MMMM D, YYYY" }}
{% else %}
Date not available
{% endif %}Updated 10 days ago