Format dates in Scriban templates
How Scriban date formatting works, what it changes in your output, and how to keep formatted dates readable, unambiguous and accessible for US and international readers.
Scriban is a text templating language for .NET. When a template prints a date, it turns a date-time value into a string. The format you choose decides whether readers understand that string correctly. This review covers what Scriban's date formatting changes, how to choose a format, and where the output can cause trouble once it is copied, shared or read by assistive technology.
A note on evidence: no tested outputs, version-specific measurements or vendor documentation were supplied for this article. The behavior described below reflects Scriban's commonly documented built-in date functions. Check it against the documentation for the Scriban version you actually run, especially the list of format specifiers and how culture is applied.
Is Scriban date formatting the right tool for your output?
Use it when a template needs to show a date to people or write it into a text format with a fixed layout. Formatting in the template keeps presentation out of your data model, and the same value can be rendered differently for different audiences.
The main tradeoff is that formatting discards information. The printed string no longer carries the time zone, the precision or the unambiguous ordering of the original value unless the format includes them. A short numeric format such as month/day/year is familiar to US readers but ambiguous to everyone else.
Use an ISO 8601 style instead, such as 2026-10-31, when another program will parse, sort or compare the output. Examples include CSV exports, file names, logs, API payloads and anything indexed by date. For mixed or international audiences, use a spelled-out month, such as 31 Oct 2026 or October 31, 2026. It avoids day/month confusion without depending on regional convention.
What the formatting step actually changes
Date formatting in Scriban is a value-to-text conversion. It is not a visual effect. The template builds new characters in its output, and the original date object in your model stays the same. No styling or display layer is involved, so the result is ordinary text that any destination receives exactly as written.
Scriban's date built-ins include date.now for the current date-time, date.parse for turning a string into a date, and date.to_string for formatting. The documented format syntax for date.to_string uses percent-prefixed specifiers similar to Ruby's strftime. If you print a date object without an explicit format, Scriban falls back to a default pattern. That default is commonly documented as day, abbreviated month and four-digit year.
{{ date.now | date.to_string '%Y-%m-%d' }}
{{ order.created | date.to_string '%B %e, %Y' }}
{{ order.created | date.to_string '%d %b %Y %H:%M' }}
The first line produces a year-month-day string. The second produces a full month name, the day and the year, which is a common US long form. The third adds a 24-hour time. Exact padding and spacing depend on the specifier. For example, %e and %d handle single-digit days differently. Confirm each specifier against your version's reference rather than assuming it behaves exactly like another language's strftime.
- Common specifiers in Scriban's strftime-style syntax (verify against your version):
- %Y — four-digit year
- %y — two-digit year
- %m — month number
- %B — full month name
- %b — abbreviated month name
- %d — day of month, zero-padded
- %e — day of month, space-padded
- %A — full weekday name
- %H — hour, 24-hour clock
- %I — hour, 12-hour clock
- %M — minutes
- %S — seconds
- %p — AM/PM marker
- %% — a literal percent sign
Two inputs affect the output besides the format string: culture and time zone.
Month and weekday names come from the culture active in the template context. The same template can therefore print different words on different servers or for different requests. Hosts can set the culture through the template context. Some function signatures also accept a culture argument, so check which mechanism your version supports.
The time zone of date.now comes from the host environment. The template does not choose it. If readers need a specific zone, convert the value in your application code before rendering, or state the zone in the output.
If you parse templates in Scriban's Liquid compatibility mode, date handling follows Liquid-style filter syntax. Templates written for one mode may not behave identically in the other, so test the mode you actually use.
Choosing a format by purpose
| Purpose | Suggested pattern | Example shape | Main caveat |
| Machine-readable, sortable | %Y-%m-%d | 2026-10-31 | Less friendly for casual readers |
| US readers, compact | %m/%d/%Y | 10/31/2026 | Ambiguous outside the US for days 1–12 |
| US readers, readable | %B %e, %Y | October 31, 2026 | Month name depends on culture |
| International readers | %d %b %Y | 31 Oct 2026 | Abbreviations vary by language |
| Timestamp with time | %Y-%m-%d %H:%M | 2026-10-31 14:05 | Zone is not shown unless you add it |
Will the formatted date stay readable after copying or sharing?
Copy and paste is not a concern with this transformation. The output is plain characters, so it copies, searches and edits like any other text. It has no special code points, no hidden direction controls and no styling that could be lost in transit.
The real risk is misreading. The string 03/04/2026 means March 4 to most US readers and 3 April to many others, and nothing in the text says which convention applies. When output may leave a US-only context, use a spelled-out month or ISO 8601. Forwarded emails, exported reports and shared documents can all leave that context.
For accessibility, screen readers may announce numeric dates as a sequence of numbers or interpret them using the user's own locale settings. No scoped screen reader test was supplied for this article, so behavior on any specific screen reader or platform is unverified. Formats with a spelled-out month name avoid depending on how the reader software interprets digit order.
In HTML output, you can show a human-friendly date and also include a machine-readable value. Wrap the visible date in a time element and give it a datetime attribute in ISO form:
<time datetime="{{ post.date | date.to_string '%Y-%m-%d' }}">{{ post.date | date.to_string '%B %e, %Y' }}</time>
Search and sorting benefit from the same principle. Year-month-day strings sort correctly as plain text. Month-first or day-first strings and month names do not. If a formatted date ends up in a file name, a table column or a search index, prefer the ISO form there, even if the visible page uses a friendlier style.
Open questions to check in your setup
- Which format specifiers your Scriban version supports, and how it pads single-digit days and hours
- Which culture is active when the template renders, and whether month names change between environments
- What time zone date.now reflects on your host, and whether stored dates are UTC or local
- Whether you render templates in standard Scriban mode or Liquid compatibility mode
- How your target screen readers announce the date formats you choose, confirmed by a test on those tools