# Date & Time Helpers

The Date & Time helpers allow you to manipulate date and time values of various formats from connectors and triggers.

## Overview

The Date & Time helpers allow you to manipulate date and time values of various formats from connectors and triggers. These are commonly used for tasks such as converting date/time values to different formats, or finding the difference between two date & time values.

## Formatting the date

A date string or timestamp can be formatted into a particular style of writing using the `Format date` operation of the Date & Time Helpers connector. For instance, '2006-01-22' is represented by `YYYY-MM-DD`, while 'Sun, January 22nd 2006' is represented by `ddd, MMMM Do YYYY`.
Note that you can escape said characters by using either `\` or `[]`. For example, when using the timezone reference: `Z`:
![date-time-helper-z](https://tray.ai/documentation/images/connectors/helper/date-time-helper/6217f764-6faa69aa_date-time-helper-z.png)

### Table of Formats

Date and Times can be represented in any way you want by combining the variables in the following table.
The Date & Time Helper connector supports time zones that are natively recognized by the JavaScript **Date** function, such as UTC, EST, and other standard time zone abbreviations.

|                                | Token              | Output                                      |
| ------------------------------ | ------------------ | ------------------------------------------- |
| **Year**                       | YY                 | 70 71 ... 29 30                             |
|                                | YYYY               | 1970 1971 ... 2029 2030                     |
| **Quarter**                    | Q                  | 1 2 3 4                                     |
|                                | Qo                 | 1st 2nd 3rd 4th                             |
| **Month**                      | M                  | 1 2 ... 11 12                               |
|                                | Mo                 | 1st 2nd ... 11th 12th                       |
|                                | MM                 | 01 02 ... 11 12                             |
|                                | MMM                | Jan Feb ... Nov Dec                         |
|                                | MMMM               | January February ... November December      |
| **Week of Year**               | W                  | 1 2 ... 52 53                               |
|                                | Wo                 | 1st 2nd ... 52nd 53rd                       |
|                                | WW                 | 01 02 ... 52 53                             |
| **Day of Year**                | DDD                | 1 2 ... 364 365                             |
|                                | DDDo               | 1st 2nd ... 364th 365th                     |
|                                | DDDD               | 001 002 ... 364 365                         |
| **Day of Month**               | D                  | 1 2 ... 30 31                               |
|                                | Do                 | 1st 2nd ... 30th 31st                       |
|                                | DD                 | 01 02 ... 30 31                             |
| **Day of Week**                | d                  | 0 1 ... 5 6                                 |
|                                | E                  | 1 2 ... 6 7                                 |
|                                | do                 | 0th 1st ... 5th 6th                         |
|                                | dd                 | Su Mo ... Fr Sa                             |
|                                | ddd                | Sun Mon ... Fri Sat                         |
|                                | dddd               | Sunday Monday ... Friday Saturday           |
| **AM/PM**                      | A                  | AM PM                                       |
|                                | a                  | am pm                                       |
| **Hour**                       | H                  | 0 1 ... 22 23                               |
|                                | HH                 | 00 01 ... 22 23                             |
|                                | h                  | 1 2 ... 11 12                               |
|                                | hh                 | 01 02 ... 11 12                             |
|                                | k                  | 1 2 ... 23 24                               |
|                                | kk                 | 01 02 ... 23 24                             |
| **Minute**                     | m                  | 0 1 ... 58 59                               |
|                                | mm                 | 00 01 ... 58 59                             |
| **Second**                     | s                  | 0 1 ... 8 9                                 |
|                                | ss                 | 00 01 ... 58 59                             |
| **Fractional Second**          | S                  | 0 1 ... 8 9                                 |
|                                | SS                 | 00 01 ... 98 99                             |
|                                | SSS                | 000 0001 ... 998 999                        |
|                                | SSSS ... SSSSSSSSS | 000\[0..] 001\[0..] ... 998\[0..] 999\[0..] |
| **Time Zone**                  | z or zz            | EST CST ... MST PST                         |
|                                | Z                  | -07:00 -06:00 ... +06:00 +07:00             |
|                                | ZZ                 | -0700 -0600 ... +0600 +0700                 |
| **Unix Timestamp**             | X                  | 1360013296                                  |
| **Unix Millisecond Timestamp** | x                  | 1360013296123                               |

## Important notes

### Comparisons

Please remember that you either need to compare two times or two dates. You cannot compare a date to a time.
![datevsdate](https://tray.ai/documentation/images/connectors/helper/date-time-helper/68osA9CHsWqZMVb7ZiyjzH_datevsdate.png)
The boolean helper can help you compare two date \*\*strings \*\*should the issue arise.
![datetime-boolean-compare](https://tray.ai/documentation/images/connectors/helper/date-time-helper/4lxqgquplREgHoI1p24oGd_datetime-boolean-compare.png)

#### Comparison example

Below is a simple walkthrough of how you can use the Date & Time Helper to compare timestamps within your workflow.
![datetime-wf-complete](https://tray.ai/documentation/images/connectors/helper/date-time-helper/6OpKsoNc5eFyd2BR4WFTPt_datetime-wf-complete.png)

### 1 - Format current time

Beginning by using the Scheduled trigger would be a more likely scenario but for the sake of testing purposes here we use the Manual trigger.
This sets step the formatting style for the comparison.
![datetime-1](https://tray.ai/documentation/images/connectors/helper/date-time-helper/14XkyytsFIX7EofU5MsuYR_datetime-1.png)

### 2 - Less than 13 hours?&#x20;

This is where the parameters for the time comparison are set and would be edited to suit your use case.
![datetime-2](https://tray.ai/documentation/images/connectors/helper/date-time-helper/70XjjsPCd24F3NC3s1HIuK_datetime-2.png)

### 3 - Compare your date/times

The boolean compares your two date/times and the result is either true or false.
![datetime-3](https://tray.ai/documentation/images/connectors/helper/date-time-helper/4xFBFp0gbcO08t55ViAQkb_datetime-3.png)

### 4 - Result

With the comparison made you would follow through with your workflow actions accordingly. Here we use the Data Storage connector to simply state the facts.
![datetime-4](https://tray.ai/documentation/images/connectors/helper/date-time-helper/447ekC6vMTUveGTVtiqM6E_datetime-4.png)

## Operations

### Get current timestamp

Gets the current date and time in the format of your choosing.
You can create a custom format if preferred.
![current-time](https://tray.ai/documentation/images/connectors/helper/date-time-helper/4HNlPBdRypT0IFq08UcSzN_current-time.png)

### Get day of the week

Retrieves the day of the week from the date specified in the format of your choosing.
![current-time](https://tray.ai/documentation/images/connectors/helper/date-time-helper/4dwSNxOGePqj4AEjV5zGJ8_dayofweek.png)
