> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://support.pdfgeneratorapi.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Date functions


##### Date
Format date value.
```
{% date({dateString}, {timezone}, {addDays}, {outputFormat}, {inputFormat}) %}
```
*Examples of the function "Date":*
* Display current time
```
{% date('now') %}
```
* Specify timezone
```
{% date({dateValue}, 'UTC') %}
```
* Specify output format
```
{% date({dateValue}, 'UTC', 0, 'd/m/Y') %}
```
* Specify output and input format
```
{% date({dateValue}, 'UTC', 0, 'd/m/Y', 'm/d/Y') %}
```

##### Datetime
Format datetime value.
```
{% datetime({datetimeString}, {timezone}, {addDays}, {outputFormat}, {inputFormat}) %}
```
*Examples of the function "Datetime":*
* Display current time
```
{% datetime('now') %}
```
* Specify timezone
```
{% datetime({dateValue}, 'UTC') %}
```
* Specify output format
```
{% datetime({dateValue}, 'UTC', 0, 'd/m/Y H:i:s') %}
```
* Specify output and input format
```
{% datetime({dateValue}, 'UTC', 0, 'd/m/Y H:i:', 'm/d/Y H:i:') %}
```

||| When using the T separator in a date format you need to escape it like this

```
Y-m-d\TH:i:s
```

##### Date difference
The `date_diff` function calculates a difference between two dates. You can also specify the `{inputFormat}` to hint date format. If date strings use known format then it is handled automatically.

|| The {inputFormat} parameter in the date_diff function is by default 'Y-m-d H:i:s'

```
{% date_diff({datetimeString}, {datetimeString}, {inputFormat}) %}
```

You can use `date('now')` function as the date value to find difference between today and another date.
```
{% date_diff(date('now'), '2021-09-15', 'Y-m-d') %}
```

|| When configuring the outputFormat and inputFormat parameters of date/datetime/date_diff function, please refer to the table below for a clear explanation of the supported formats. This will ensure the Date component processes and displays dates as intended.

| **Format** | **Description** | **Example Output** |
| ---- |
| **Day** |  |  |
| `d` | The day of the month (two digits, leading zeros) | 01 to 31 |
| `D` | A textual representation of a day (three letters) | Mon through Sun |
| `j` | The day of the month without leading zeros | 1 to 31 |
| `l` | A full textual representation of the day | Sunday through Saturday |
| `N` | ISO-8601 numeric representation of the day (1 = Monday, 7 = Sunday) | 1 to 7 |
| `S` | English ordinal suffix for the day of the month (2 characters: st, nd, rd, or th) | 1st, 2nd, 3rd |
| `w` | Numeric representation of the day (0 = Sunday, 6 = Saturday) | 0 to 6 |
| `z` | The day of the year | 0 through 365 |
| **Week** |  |  |
| `W` | ISO-8601 week number of year (weeks starting on Monday) | 01 to 53 |
| **Month** |  |  |
| `F` | A full textual representation of a month | January through December |
| `m` | Numeric representation of a month (two digits, leading zeros) | 01 to 12 |
| `M` | A short textual representation of a month (three letters) | Jan through Dec |
| `n` | Numeric representation of a month (without leading zeros) | 1 to 12 |
| `t` | The number of days in the given month | 28 to 31 |
| **Year** |  |  |
| `L` | Whether it's a leap year (1 if it is a leap year, 0 otherwise) | 0 or 1 |
| `o` | ISO-8601 year number | 2023 |
| `Y` | A full numeric representation of a year (four digits) | 2023 |
| `y` | A two-digit representation of a year | 23 |
| **Time** |  |  |
| `a` | Lowercase am or pm | am, pm |
| `A` | Uppercase AM or PM | AM, PM |
| `B` | Swatch Internet time | 000 to 999 |
| `g` | 12-hour format of an hour (no leading zeros) | 1 to 12 |
| `G` | 24-hour format of an hour (no leading zeros) | 0 to 23 |
| `h` | 12-hour format of an hour (two digits, leading zeros) | 01 to 12 |
| `H` | 24-hour format of an hour (two digits, leading zeros) | 00 to 23 |
| `i` | Minutes with leading zeros | 00 to 59 |
| `s` | Seconds, with leading zeros | 00 to 59 |
| `u` | Microseconds | 654321 |
| **Timezone** |  |  |
| `e` | Timezone identifier | UTC, GMT, Europe/Paris |
| `I` | Whether the date is in Daylight Savings Time (1 if DST, 0 otherwise) | 0 or 1 |
| `O` | Difference to Greenwich time (GMT) in hours | +0200 |
| `P` | Difference to Greenwich time (GMT) with colon between hours and minutes | +02:00 |
| `T` | Timezone abbreviation | EST, MDT |
| `Z` | Timezone offset in seconds (west of UTC is negative, east of UTC is positive) | -43200 to 50400 |
| **Full Date/Time** |  |  |
| `c` | ISO-8601 date | 2023-01-14T23:59:59+00:00 |
| `r` | RFC 2822 formatted date | Sat, 14 Jan 2023 23:59:59 +0000 |
| `U` | Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) | 1673740799 |
---
### Related articles you may find helpful

* [Date component](https://support.pdfgeneratorapi.com/en/article/date-component-fxrycs/)
* [How to add page numbers?](https://support.pdfgeneratorapi.com/en/article/how-to-add-page-numbers-1re50ta/)
* [Is it possible to conditionally change the component style or hide the component?](https://support.pdfgeneratorapi.com/en/article/is-it-possible-to-conditionally-change-the-component-style-or-hide-the-component-z8nmwg/)
