# formatdatetime: Format Date and Time

> formatdatetime (Format Date and Time) is a 1001fx API function in the group Date & time: POST https://api.1001fx.com/datetime/formatdatetime, 1 credit per call. It works as a ready-made module in n8n or as a plain HTTP call.

Formats a date and time into the output format you specify, e.g. YYYY-MM-DD or DD.MM.YYYY HH:mm.

- Group: Date & time
- Endpoint: `POST https://api.1001fx.com/datetime/formatdatetime`
- Authentication: header `X-API-KEY: YOURSECRETAPIKEY`
- Content type: application/json
- Credits: 1 credit per call
- Ready-made in: n8n
- Docs: https://1001fx.com/functions/formatdatetime

## Parameters

- `date` (string, required) – Date: The date to format. If Formats to test is not provided, your date needs to be in one of the following formats DD.MM.YYYY, DD.MM.YY, DD.MM.YYYY HH:mm, DD.MM.YY HH:mm, MM-DD-YYYY, MM-DD-YYYY HH:mm, MM-DD-YY, MM-DD-YY HH:mm.
- `format` (string, required) – Output Format: The desired output format.
- `formatsToTest` (array<string>, optional) – Formats to test: The formats the date can be in.

## Use cases

- Convert a US date from a form into DD.MM.YYYY for a German CRM
- Format timestamps for email subjects and file names
- Bring dates from several sources into one format before you compare them

## Example: Format DD.MM.YY

```bash
curl -X POST 'https://api.1001fx.com/datetime/formatdatetime' \
  -H 'X-API-KEY: YOURSECRETAPIKEY' \
  -H 'Content-Type: application/json' \
  -d '{"date":"14/08/22","format":"DD.MM.YYYY HH:mm","formatsToTest":["MM/DD/YY","DD/MM/YY","YY/MM/DD","YY.MM.DD HH:mm"]}'
```

Answer (HTTP 200):

```json
{
  "result": "14.08.2022 00:00"
}
```

## FAQ

**Which input formats are accepted?**

Without formatsToTest: DD.MM.YYYY, DD.MM.YY and MM-DD-YYYY, MM-DD-YY, each with or without a time in HH:mm. For other inputs list the possible formats in formatsToTest.

**How do I describe the output format?**

With tokens such as DD for the day, MM for the month, YYYY for the year, HH for the hour and mm for the minutes, for example DD.MM.YYYY HH:mm.
