Formatting Dates in Liquid
When working with Onboarded, you may encounter dates related to employee onboarding, such as when an employee signed a document, their date of birth, or their hiring date. To display these dates in a readable format, you can use Liquid’s date
filter.
The date
filter allows you to convert raw date values into user-friendly formats. This is useful when displaying dates in emails, documents, or within your onboarding platform.
How the date
Filter Works
The date
filter takes a date value (e.g., employee.dob
) and formats it according to the specified format string.
Basic Syntax
{{ employee.signature.signed_at | date: "%B %d, %Y" }}
This would output: "February 6, 2025" (assuming the signing date was February 6, 2025).
Common Use Cases & Examples
1. Display an Employee's Date of Birth
{{ employee.dob | date: "%B %d, %Y" }}
➡️ Outputs: "July 15, 1990"
2. Show the Hire Date in a Formal Format
{{ form.hired_date | date: "%A, %B %d, %Y" }}
➡️ Outputs: "Monday, June 10, 2024"
3. Display a Signed Date with Time
{{ employee.signature.signed_at | date: "%B %d, %Y at %I:%M %p" }}
➡️ Outputs: "February 6, 2025 at 02:30 PM"
4. Show the Hire Date in a Shorter Format
{{ form.hired_date | date: "%d-%m-%Y" }}
➡️ Outputs: "10-06-2024"
5. Show Only the Year of Birth
{{ employee.dob | date: "%Y" }}
➡️ Outputs: "1990"
Date Formatting Options
Below is a reference table for Liquid date format options:
Format | Description | Example Output (for February 6, 2025) |
---|---|---|
%Y | Full year (4 digits) | 2025 |
%y | Short year (last 2 digits) | 25 |
%m | Month (01-12) | 02 |
%B | Full month name | February |
%b | Abbreviated month name | Feb |
%d | Day of the month (01-31) | 06 |
%e | Day of the month (1-31, no zero-padding) | 6 |
%A | Full weekday name | Thursday |
%a | Abbreviated weekday name | Thu |
%H | Hour (24-hour format, 00-23) | 14 |
%I | Hour (12-hour format, 01-12) | 02 |
%p | AM or PM | PM |
%M | Minutes (00-59) | 30 |
%S | Seconds (00-59) | 45 |
%Z | Time zone name | UTC |
%z | Time zone offset | +0000 |
Conclusion
By using Liquid’s date
filter, you can easily format onboarding-related dates in a way that is clear and professional. Whether you’re displaying hiring dates, birthdates, or document signing times, this feature ensures a polished and user-friendly experience.
For more advanced formatting options, refer to Liquid documentation.