# FormatDate

{% hint style="info" %}
The **`FormatDate()`** function converts a <mark style="color:blue;">date</mark> to a specified format.&#x20;

Typical elements that can be used in the date format:\
yyyy: full year;\
MM: month number with leading zero;\
dd: day-number with leading zero;\
HH: 24-hour time with leading zero;\
h: 12-hour time without leading zero;\
mm: minutes with leading zero;\
ss: seconds with leading zero;\
fff: fraction of a second (milliseconds in this case).

See the \[Microsoft documentation] (<https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx>) to learn more about format strings.

This function is NOT SQL compatible. For more information about SQL compatibility, see our [documentation](https://docs.wem.io/platform/~/changes/y5gAfiyi2fILzrLzUUHj/wemreference/sql-compatibility).
{% endhint %}

{% hint style="success" %}
Returns a new <mark style="color:green;">text</mark> string that is the text representation of a date.\
Returns <mark style="color:red;">`Invalid expression`</mark> if <mark style="color:blue;">`Date`</mark>is unknown or the indicated format is not valid for dates.&#x20;
{% endhint %}

### Syntax

<details>

<summary><code>FormatDate(</code><mark style="color:blue;"><code>date</code></mark><code>,</code><mark style="color:blue;"><code>format</code></mark><code>)</code></summary>

`FormatDate(Now(), "MM-dd-yyyy")`\
\&#xNAN;*=> "05-13-2022"*

</details>

<details>

<summary><code>FormatDate(</code><mark style="color:blue;"><code>date</code></mark><code>,</code><mark style="color:blue;"><code>language</code></mark><code>)</code></summary>

`FormatDate(Now(), en_US)`\
\&#xNAN;*=> "5/13/2022 01:54:00 PM"*

</details>

### Parameters

<table><thead><tr><th width="150">Name</th><th width="150">Type</th><th width="150" align="center">Required</th><th width="248.15953250810662">Description</th><th data-hidden>Required?</th></tr></thead><tbody><tr><td><mark style="color:blue;"><code>date</code></mark></td><td>date time</td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="2611">☑️</span></td><td>a date</td><td>yes</td></tr><tr><td><mark style="color:blue;"><code>format</code></mark></td><td>text or formatstring</td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="2611">☑️</span></td><td>the format is used to specify how the date should be represented, text or a format string can be used.</td><td></td></tr><tr><td><mark style="color:blue;"><code>language</code></mark></td><td>text</td><td align="center"><span data-gb-custom-inline data-tag="emoji" data-code="2611">☑️</span></td><td>this parameter is used to specify the date representation of that language</td><td></td></tr></tbody></table>

### Format strings

| Format name   | Example                    | Description                                                               |
| ------------- | -------------------------- | ------------------------------------------------------------------------- |
| ShortDate     | 8-4-2022                   | day month and year in numbers.                                            |
| ShortDateTime | 8-4-2022 17:51             | day, month, year and time in numbers                                      |
| LongDate      | vrijdag 8 april 2022       | day of the week and month in text with the day and year in numbers.       |
| LongDateTime  | vrijdag 8 april 2022 17:51 | day of the week and month in text with the day, year and time in numbers. |
| Iso8601       | 2022-04-08T17:51:38        | date in the [iso8601 ](https://en.wikipedia.org/wiki/ISO_8601)standard    |

{% hint style="warning" %}
When using a format string, the separator and order of your date is dependent on your date settings. You can find and change this setting per portal, [see more about portal and language settings here. ](https://docs.wem.io/platform/~/changes/y5gAfiyi2fILzrLzUUHj/wemmodeler/project-settings/portal-settings#change-language-settings)

If the `format` or `language` parameter contains an unknown value, then the default portal language is used to format the string.
{% endhint %}
