---
title: "Formatting dates"
description: "Format and display dates and times in generated documents with customised layouts, including handling various input and output formats and showing the current date."
canonical_url: "https://resources.docmosis.com/template-tutorials/format-dates"
last_reviewed: 2026-06-08
---

# Formatting dates

Docmosis allows you to control how dates and times are displayed in the finished document.

For example: the raw data may have a date like: 21\-03\-16.

Using the built\-in function dateFormat the date can be formatted so that it looks like this: Monday \- March 21, 2016\.

It is best to view the TEMPLATE and OUTPUT files side\-by\-side to understand the formatting that has been applied.

### Parameters for dateFormat

The function dateFormat has up to three parameters. 

All three parameters are used in the statement  dateFormat ( value \[, outputFormat \[, inputFormat] ]). The first parameter contains the date/time.

| value | is the Date/Time to be formatted |
| --- | --- |

The other two are the format strings, enclosed in single quotes.

| inputFormat | used to tell Docmosis how to decode the value that is passed in |
| --- | --- |
| outputFormat | used to tell Docmosis how to display the decoded value |

### Format strings

Here is an example of a format string: 'dd\-MMMM\-yyyy'.

If they are not provided \- Docmosis will use the default settings.

Some characters in the string are standard:

| dd | for a two digit day |
| --- | --- |
| yyyy | for a four digit year |

Other combinations are not so obvious:

| MM | is the Month in numeric format |
| --- | --- |
| MMM | is the Month abbreviated to the first three letters |
| MMMM | is the Month as a full word |
| mm | is for minutes |
| EEEE | the day expressed as a word |
| EEE | the day abbreviated to the first three letters |
| hh | is for hours in 12 hour notation |
| HH | is for hours in 24 hour notation |
| aa | is for AM/PM |

You will find the complete list in the [Template Guide](/template-guide-mod).

### Displaying the current date/time.

Docmosis has a built\-in variable that can be used to insert the current date and time:

```
<<$nowUTC>>
```

Please refer to the FAQ: [How can I insert the current date / time?](/faq/how-can-i-insert-the-current-date-time) for details on how to use it with the dateFormat function.

# Formatting dates - related json data

```json
{
  "dateOne": "21-Mar-2016",
  "dateTwo": "21/03/2016 10:06pm",
  "dateThree": "2016-03-21T00:00:00Z",
  "dateFour": "21-3-2016 at 22:06:17"
}
```

# Formatting dates - example template syntax

```docmosis
**Formatting Dates**

Docmosis has a built\-in function to format dates:

 ***dateFormat ( value \[, outputFormat \[, inputFormat] ])***

The parameters are:

***value*** *\= the incoming Date to format*

***inputFormat (optional)*** *\= a string that is use to decode the input date*

 ***outputFormat (optional)*** *\= a string that represents the format to use for output*

The ***inputFormat***and ***outputFormat*** strings should be enclosed in single quotes.

**Example 1: inputFormat \= not set**

If no *inputFormat* is specified Docmosis will try to decode the incoming *value* using a set of standard *inputFormats*.

**Date to format : \<\\>**

| outputFormat | Output Result |
| --- | --- |
| dd/MM/yy | \<\<{dateFormat(dateOne, ‘dd/MM/yy’)}\>\> |

If the incoming *value* doesn’t match a known format (and Docmosis is in DEV mode) then an error will be injected in to the finished document.

**Date to format : \<\\>**

| outputFormat | Result |
| --- | --- |
| dd/MM/yy | \<\<{dateFormat(dateTwo, ‘dd/MM/yy’)}\>\> |

**Example 2: outputFormat \= not set**

If *outputFormat* is not set Docmosis will use the default format ‘dd MMM yyyy’.

**Date to format : \<\\>**

| outputFormat | Output Result |
| --- | --- |
| Not specified | \<\<{dateFormat(dateThree)}\>\> |

*Note: in the above example the Date to format is decoded using one of the known standard formats: ‘yyyy\-MMdd'T'HH:mm:ss'Z'’. The list of possible standard inputFormats that will be used can be configured to suit your application.*

**Example 3: A selection of outputFormat’s**

**Date to format : \<\\>**

| outputFormat | Output Result |
| --- | --- |
| dd/MM/yy | \<\<{dateFormat(dateOne, ‘dd/MM/yy’)}\>\> |
| MM\-dd\-yyyy | \<\<{dateFormat(dateOne, ‘MM\-dd\-yyyy’)}\>\> |
| MMMM dd, yyyy | \<\<{dateFormat(dateOne, ‘MMMM dd, yyyy’)}\>\> |
| hh:mmaa \- MMMM dd | \<\<{dateFormat(dateOne, ‘hh:mmaa \- MMMM dd’)}\>\> |
| EEEE, dd 'of' MMMM, yyyy | \<\<{dateFormat(dateOne, ‘EEEE, dd 'of' MMMM, yyyy’)}\>\> |

*Notice that in the last example above – the outputFormat string is enclosed in curly single quotes and the word 'of' is enclosed in straight quotes. This is a very subtle difference.*

*Straight quotes can be used to delimit characters in the formatting string that should pass straight through and not be interpreted as elements of the date. Characters not in straight quotes will be used to decode the values of day/month/year/time.***Example 4: Specifying inputFormat’s**

If an *inputFormat* is specified Docmosis will try to decode the incoming *value* using the *inputFormat* pattern.

**Date to format : \<\\>**

**inputFormat : ‘dd/MM/yyyy hh:mmaa’**

| outputFormat | Result |
| --- | --- |
| MM/dd/yy | \<\<{dateFormat(dateTwo, ‘MM/dd/yy’,‘dd/MM/yyyy hh:mmaa’)}\>\> |
| dd\-MMM\-yy | \<\<{dateFormat(dateTwo, ‘dd\-MMM\-yy’,‘dd/MM/yyyy hh:mmaa’)}\>\> |
| HH:mm | \<\<{dateFormat(dateTwo, ‘HH:mm’,‘dd/MM/yyyy hh:mmaa’)}\>\> |

**Date to format : \<\\>**

**inputFormat : ‘MM\-dd\-yyyy 'at' HH:mm:ss’**

| outputFormat | Result |
| --- | --- |
| MM/dd/yy | \<\<{dateFormat(dateFour, ‘MM/dd/yy’,‘MM\-dd\-yyyy 'at' HH:mm:ss’)}\>\> |
| dd\-MMM\-yy | \<\<{dateFormat(dateFour, ‘dd\-MMM\-yy’,‘MM\-dd\-yyyy 'at' HH:mm:ss’)}\>\> |
| hh:mm aa | \<\<{dateFormat(dateFour, ‘hh:mm aa’,‘MM\-dd\-yyyy 'at' HH:mm:ss’)}\>\> |

**Date to format : \<\\>**

**inputFormat : ‘MM\-dd\-yyyy’**

| outputFormat | Result |
| --- | --- |
| dd/MM/yy | \<\<{dateFormat(dateFour, ‘dd/MM/yy’,‘MM\-dd\-yyyy’)}\>\> |

*In DEV mode, if the incoming value doesn’t match the inputFormat then an error is injected.*
```