Date & Time Functions Guide
Last updated: October 12, 2025
Date & 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
dateFormat Function
The dateFormat function converts date strings into formatted output using Go's date layout patterns.
Basic Syntax
{{dateFormat .DateField "layout"}}
Supported Input Formats
The function automatically parses these 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>
Sample Data:
{
"InvoiceDate": "2025-09-21"
}
Output:
<p>Date: September 21, 2025</p>
Date Format Layouts
Go uses a reference date/time to specify formats: Mon Jan 2 15:04:05 MST 2006
Basic Components
2006: Four-digit year06: Two-digit yearJanuary: Full month nameJan: Abbreviated month (3 letters)01: Two-digit month (01-12)1: Month without leading zero02: Two-digit day (01-31)2: Day without leading zeroMonday: Full weekday nameMon: Abbreviated weekday
Time Components
03: Two-digit hour (01-12)3: Hour without leading zero15: Two-digit hour (00-23)04: Two-digit minute (00-59)4: Minute without leading zero05: Two-digit second (00-59)5: Second without leading zeroPM: Uppercase AM/PMpm: Lowercase am/pmMST: Timezone abbreviation-0700: Timezone offset
Common Date Patterns
Full Date Formats
<!-- Long Format: September 21, 2025 -->
{{dateFormat .Date "January 2, 2006"}}
<!-- Medium Format: Sep 21, 2025 -->
{{dateFormat .Date "Jan 2, 2006"}}
<!-- Short Format: 09/21/2025 -->
{{dateFormat .Date "01/02/2006"}}
<!-- ISO Format: 2025-09-21 -->
{{dateFormat .Date "2006-01-02"}}
<!-- European Format: 21/09/2025 -->
{{dateFormat .Date "02/01/2006"}}
<!-- With Weekday: Sunday, September 21, 2025 -->
{{dateFormat .Date "Monday, January 2, 2006"}}
<!-- Abbreviated: Sun, Sep 21, 2025 -->
{{dateFormat .Date "Mon, Jan 2, 2006"}}
Real-World Examples
Example 1: Invoice Header
<div class="invoice-header">
<h1>INVOICE</h1>
<div class="invoice-info">
<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>
</div>
Date Format Cheat Sheet
Quick Reference
2006: Year (four digits)06: Year (two digits)January: Month (full name)Jan: Month (abbreviated)01: Month (two digits)1: Month (no leading zero)02: Day (two digits)2: Day (no leading zero)Monday: Weekday (full name)Mon: Weekday (abbreviated)15: Hour (24-hour, two digits)03: Hour (12-hour, two digits)3: Hour (12-hour, no leading zero)04: Minute (two digits)4: Minute (no leading zero)05: Second (two digits)5: Second (no leading zero)PM: AM/PM (uppercase)pm: AM/PM (lowercase)MST: Timezone (abbreviation)-0700: Timezone (numeric offset)
Common Layouts
- "2006-01-02" →
2025-09-21 - "01/02/2006" →
09/21/2025 - "02/01/2006" →
21/09/2025 - "January 2, 2006" →
September 21, 2025 - "Jan 2, 2006" →
Sep 21, 2025 - "Monday, January 2, 2006" →
Sunday, September 21, 2025 - "Mon, Jan 2, 2006" →
Sun, Sep 21, 2025 - "15:04" →
15:30 - "3:04 PM" →
3:30 PM - "2006-01-02 15:04:05" →
2025-09-21 15:30:45 - "Jan 2, 2006 at 3:04 PM" →
Sep 21, 2025 at 3:30 PM
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 that your input date is in one of these formats:
- RFC3339:
2025-09-21T15:30:00Z - Date:
2025-09-21 - DateTime:
2025-09-21T15:30:00
Wrong Output?
Remember Go's reference date: January 2, 2006 at 3:04:05 PM
- Use
01for month, notMM - Use
02for day, notDD - Use
2006for year, notYYYY
Quick Tip: The reference date is Mon Jan 2 15:04:05 MST 2006 - a memorable sequence: 1/2 3:04:05 2006!