Date & Time Functions Guide
Updated Mar 28, 2026
DataMagik DocumentsDate & Time Functions Guide
Format dates and timestamps in your document templates with powerful formatting options.
Table of Contents
- dateFormat Function
- Date Format Layouts
- Common Date Patterns
- Real-World Examples
- Best Practices
1. dateFormat Function
The dateFormat function converts date strings into formatted output using Go's date layout patterns.
Syntax
{{dateFormat .DateField "layout"}}Supported Input Formats
- RFC3339:
2025-09-21T15:30:00Z - Date only:
2025-09-21 - DateTime:
2025-09-21T15:30:00
Example
<p>Date: {{dateFormat .InvoiceDate "January 2, 2006"}}</p>
<!-- Input: "2025-09-21" → Output: September 21, 2025 -->2. Date Format Layouts
Go uses a reference date/time to specify formats: Mon Jan 2 15:04:05 MST 2006
Date Components
| Pattern | Description | Example |
|---|---|---|
2006 | Four-digit year | 2025 |
06 | Two-digit year | 25 |
January | Full month name | September |
Jan | Abbreviated month | Sep |
01 | Two-digit month | 09 |
1 | Month (no leading zero) | 9 |
02 | Two-digit day | 21 |
2 | Day (no leading zero) | 21 |
Monday | Full weekday name | Sunday |
Mon | Abbreviated weekday | Sun |
Time Components
| Pattern | Description | Example |
|---|---|---|
15 | Hour (24-hour) | 15 |
03 | Hour (12-hour, padded) | 03 |
3 | Hour (12-hour) | 3 |
04 | Minute (padded) | 30 |
05 | Second (padded) | 45 |
PM | AM/PM (uppercase) | PM |
pm | AM/PM (lowercase) | pm |
MST | Timezone abbreviation | EST |
-0700 | Timezone offset | -0500 |
3. Common Date Patterns
<!-- Long: September 21, 2025 -->
{{dateFormat .Date "January 2, 2006"}}
<!-- Medium: Sep 21, 2025 -->
{{dateFormat .Date "Jan 2, 2006"}}
<!-- Short US: 09/21/2025 -->
{{dateFormat .Date "01/02/2006"}}
<!-- ISO: 2025-09-21 -->
{{dateFormat .Date "2006-01-02"}}
<!-- European: 21/09/2025 -->
{{dateFormat .Date "02/01/2006"}}
<!-- With weekday: Sunday, September 21, 2025 -->
{{dateFormat .Date "Monday, January 2, 2006"}}
<!-- With time: Sep 21, 2025 at 3:30 PM -->
{{dateFormat .Date "Jan 2, 2006 at 3:04 PM"}}
<!-- Full datetime: 2025-09-21 15:30:45 -->
{{dateFormat .Date "2006-01-02 15:04:05"}}4. Real-World Examples
Invoice Header
<div class="invoice-header">
<h1>INVOICE</h1>
<p><strong>Invoice Number:</strong> {{.InvoiceNumber}}</p>
<p><strong>Invoice Date:</strong> {{dateFormat .InvoiceDate "January 2, 2006"}}</p>
<p><strong>Due Date:</strong> {{dateFormat .DueDate "January 2, 2006"}}</p>
<p><strong>Issued:</strong> {{dateFormat .IssuedDateTime "Jan 2, 2006 at 3:04 PM"}}</p>
</div>5. Best Practices
- Be Consistent — Use the same date format throughout a document
- Consider Audience — Use regional formats appropriate for your users
- Include Timezone — For time-sensitive documents, include timezone information
- Use Full Dates — For legal documents, use full date formats (e.g., "January 2, 2006")
- Test Edge Cases — Verify formatting with dates at month/year boundaries
Troubleshooting
- Date not formatting? — Check input is RFC3339, Date, or DateTime format
- Wrong output? — Remember Go's reference date: use
01for month (not MM),02for day (not DD),2006for year (not YYYY)
Tip: The reference date is Mon Jan 2 15:04:05 MST 2006 — a memorable sequence: 1/2 3:04:05 2006.