> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fileloom.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Date & Time Helpers

> Format and manipulate dates with formatDate, formatTime, now, addDays, daysBetween, and more.

Date and time helpers format and manipulate date values.

## formatDate

Formats a date according to a pattern.

```handlebars theme={null}
{{formatDate date "YYYY-MM-DD"}}
{{formatDate date "MMMM D, YYYY"}}
```

| Argument | Type        | Default      | Description    |
| -------- | ----------- | ------------ | -------------- |
| `date`   | string/Date | required     | Date to format |
| `format` | string      | "YYYY-MM-DD" | Format pattern |

### Format Tokens

| Token  | Output           | Example  |
| ------ | ---------------- | -------- |
| `YYYY` | 4-digit year     | 2024     |
| `YY`   | 2-digit year     | 24       |
| `MMMM` | Full month name  | December |
| `MMM`  | Short month name | Dec      |
| `MM`   | 2-digit month    | 12       |
| `M`    | Month number     | 12       |
| `DD`   | 2-digit day      | 05       |
| `D`    | Day number       | 5        |

### Examples

```handlebars theme={null}
{{formatDate "2024-12-15" "YYYY-MM-DD"}}
```

**Output:** `2024-12-15`

```handlebars theme={null}
{{formatDate "2024-12-15" "MMMM D, YYYY"}}
```

**Output:** `December 15, 2024`

```handlebars theme={null}
{{formatDate "2024-12-15" "MMM D, YYYY"}}
```

**Output:** `Dec 15, 2024`

```handlebars theme={null}
{{formatDate "2024-12-15" "MM/DD/YYYY"}}
```

**Output:** `12/15/2024`

```handlebars theme={null}
{{formatDate "2024-12-15" "D MMMM YYYY"}}
```

**Output:** `15 December 2024`

## formatTime

Formats the time portion of a date.

```handlebars theme={null}
{{formatTime datetime "24"}}
{{formatTime datetime "12"}}
```

| Argument | Type        | Default  | Description              |
| -------- | ----------- | -------- | ------------------------ |
| `date`   | string/Date | required | Date/time to format      |
| `format` | string      | "24"     | "12" or "24" hour format |

**Examples:**

```handlebars theme={null}
{{formatTime "2024-12-15T14:30:00" "24"}}
```

**Output:** `14:30`

```handlebars theme={null}
{{formatTime "2024-12-15T14:30:00" "12"}}
```

**Output:** `2:30 PM`

## formatDateTime

Combines date and time formatting.

```handlebars theme={null}
{{formatDateTime datetime "MMMM D, YYYY" "12"}}
```

| Argument     | Type        | Default      | Description              |
| ------------ | ----------- | ------------ | ------------------------ |
| `date`       | string/Date | required     | Date/time to format      |
| `dateFormat` | string      | "YYYY-MM-DD" | Date format pattern      |
| `timeFormat` | string      | "24"         | "12" or "24" hour format |

**Examples:**

```handlebars theme={null}
{{formatDateTime "2024-12-15T14:30:00" "MMM D, YYYY" "12"}}
```

**Output:** `Dec 15, 2024 2:30 PM`

## now

Returns the current date/time formatted.

```handlebars theme={null}
{{now}}
{{now "MMMM D, YYYY"}}
```

| Argument | Type   | Default      | Description    |
| -------- | ------ | ------------ | -------------- |
| `format` | string | "YYYY-MM-DD" | Format pattern |

**Examples:**

```handlebars theme={null}
{{now}}
```

**Output:** `2024-12-15`

```handlebars theme={null}
{{now "MMMM D, YYYY"}}
```

**Output:** `December 15, 2024`

```handlebars theme={null}
Generated on: {{now "MMM D, YYYY"}}
```

## addDays

Adds days to a date.

```handlebars theme={null}
{{addDays date 30}}
{{addDays date -7}}
```

| Argument | Type        | Default  | Description                        |
| -------- | ----------- | -------- | ---------------------------------- |
| `date`   | string/Date | required | Starting date                      |
| `days`   | number      | 0        | Days to add (negative to subtract) |

**Examples:**

```handlebars theme={null}
{{addDays "2024-12-15" 30}}
```

**Output:** `2025-01-14`

```handlebars theme={null}
{{addDays "2024-12-15" -7}}
```

**Output:** `2024-12-08`

**Use case - Due dates:**

```handlebars theme={null}
<p>Invoice Date: {{formatDate invoiceDate "MMM D, YYYY"}}</p>
<p>Due Date: {{formatDate (addDays invoiceDate 30) "MMM D, YYYY"}}</p>
```

## daysBetween

Calculates the number of days between two dates.

```handlebars theme={null}
{{daysBetween startDate endDate}}
{{daysBetween startDate}}
```

| Argument | Type        | Default  | Description |
| -------- | ----------- | -------- | ----------- |
| `date1`  | string/Date | required | First date  |
| `date2`  | string/Date | now      | Second date |

**Examples:**

```handlebars theme={null}
{{daysBetween "2024-12-01" "2024-12-15"}}
```

**Output:** `14`

```handlebars theme={null}
{{! Days until due date }}
{{daysBetween (now) dueDate}} days remaining
```

## monthName

Returns the full name of the month.

```handlebars theme={null}
{{monthName date}}
```

**Examples:**

```handlebars theme={null}
{{monthName "2024-12-15"}}
```

**Output:** `December`

## dayName

Returns the name of the day of the week.

```handlebars theme={null}
{{dayName date}}
```

**Examples:**

```handlebars theme={null}
{{dayName "2024-12-15"}}
```

**Output:** `Sunday`

## Practical Examples

### Invoice Header

```handlebars theme={null}
<div class="invoice-header">
  <h1>Invoice #{{invoiceNumber}}</h1>
  <div class="dates">
    <p><strong>Invoice Date:</strong> {{formatDate invoiceDate "MMMM D, YYYY"}}</p>
    <p><strong>Due Date:</strong> {{formatDate dueDate "MMMM D, YYYY"}}</p>
  </div>
</div>
```

### Payment Terms

```handlebars theme={null}
<div class="payment-terms">
  <p>Payment due within 30 days</p>
  <p>Invoice Date: {{formatDate invoiceDate "MMM D, YYYY"}}</p>
  <p>Due Date: {{formatDate (addDays invoiceDate 30) "MMM D, YYYY"}}</p>
</div>
```

### Document Footer

```handlebars theme={null}
<footer>
  <p>Generated on {{now "MMMM D, YYYY"}} at {{formatTime (now) "12"}}</p>
</footer>
```

### Event Details

```handlebars theme={null}
<div class="event">
  <h2>{{eventName}}</h2>
  <p class="date">
    {{dayName eventDate}}, {{formatDate eventDate "MMMM D, YYYY"}}
  </p>
  <p class="time">
    {{formatTime startTime "12"}} - {{formatTime endTime "12"}}
  </p>
</div>
```

### Overdue Notice

```handlebars theme={null}
{{#if (gt (daysBetween dueDate) 0)}}
  <div class="overdue-notice">
    <p>This invoice is {{daysBetween dueDate}} days overdue.</p>
  </div>
{{/if}}
```

### Report Period

```handlebars theme={null}
<div class="report-header">
  <h1>Monthly Report</h1>
  <p>{{monthName periodStart}} {{formatDate periodStart "YYYY"}}</p>
  <p>{{formatDate periodStart "MMM D"}} - {{formatDate periodEnd "MMM D, YYYY"}}</p>
</div>
```
