Date & Time Functions Guide

Updated Mar 28, 2026
DataMagik Documents

Date & Time Functions Guide

Format dates and timestamps in your document templates with powerful formatting options.

Table of Contents

  1. dateFormat Function
  2. Date Format Layouts
  3. Common Date Patterns
  4. Real-World Examples
  5. 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

PatternDescriptionExample
2006Four-digit year2025
06Two-digit year25
JanuaryFull month nameSeptember
JanAbbreviated monthSep
01Two-digit month09
1Month (no leading zero)9
02Two-digit day21
2Day (no leading zero)21
MondayFull weekday nameSunday
MonAbbreviated weekdaySun

Time Components

PatternDescriptionExample
15Hour (24-hour)15
03Hour (12-hour, padded)03
3Hour (12-hour)3
04Minute (padded)30
05Second (padded)45
PMAM/PM (uppercase)PM
pmAM/PM (lowercase)pm
MSTTimezone abbreviationEST
-0700Timezone 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 01 for month (not MM), 02 for day (not DD), 2006 for 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.

Was this page helpful?