# Date Display Format

Canonical page: https://www.adaptabletools.com/docs/handbook-column-formatting-display-format-date

- AdapTable provides a number of Display Formats to be used with Date Columns

Users can use the [`Date Formatter`](https://www.adaptabletools.com/docs/reference/dateformatteroptions.md) to set their own date pattern (or select one of the presets).

The object has a single `Pattern` property:

| Property | Type | Description |
| --- | --- | --- |
| [Pattern](https://www.adaptabletools.com/docs/reference/dateformatteroptions.md#pattern) | `string` | Pattern to use for Date Format |

Find the full list of available DateTime patterns at the [unicode website](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table)

### Date Presets

Similar to numeric columns, AdapTable provides some presets for commonly used Date Formats:

| Preset                  | Example (using 5 August 2023 at 10:30pm) |
| ----------------------- | ---------------------------------------- |
| MM/dd/yyyy              | 08/05/2023                               |
| dd-MM-yyyy              | 05-08-2023                               |
| MMMM do yyyy, h:mm:ss a | August 5th 2023, 10:30:00 PM             |
| EEEE                    | Saturday                                 |
| MMM do yyyy             | Aug 5th 2023                             |
| yyyyMMdd                | 20230805                                 |
| HH:mm:ss                | 22:30:00                                 |

**Example: Column Formatting: Date Display Formats**

Column Formatting with Date Display Formats

- This example shows 3 different Date Formats 
  - `Created` has a format of 'yyyy/MM/dd'
  - `Updated` has a format of 'MMM do yyyy'
  - `Pushed` has a format of 'EEEE'
  
### Expand to see the Date Display Formats

```ts
FormatColumn: {
  FormatColumns: [
    {
      Name: 'FormatColumn-created_at-112',
      Scope: {
        ColumnIds: ['created_at'],
      },
      DisplayFormat: {
        Formatter: 'DateFormatter',
        Options: {
          Pattern: 'yyyy/MM/dd',
        },
      },
    },
    {
      Name: 'FormatColumn-updated_at-113',
      Scope: {
        ColumnIds: ['updated_at'],
      },
      DisplayFormat: {
        Formatter: 'DateFormatter',
        Options: {
          Pattern: 'MMM do yyyy',
        },
      },
    },
    {
      Name: 'FormatColumn-pushed_at-114',
      Scope: {
        ColumnIds: ['pushed_at'],
      },
      DisplayFormat: {
        Formatter: 'DateFormatter',
        Options: {
          Pattern: 'EEEE',
        },
      },
    },
  ],
},
```

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Date Display Formats',
  initialState: {
    Dashboard: {
      ModuleButtons: ['FormatColumn'],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'language',
            'created_at',
            'updated_at',
            'pushed_at',
            'week_issue_change',
            'github_stars',
            'closed_pr_count',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
    FormatColumn: {
      FormatColumns: [
        {
          Name: 'formatColumn-created_at',
          Scope: {
            ColumnIds: ['created_at'],
          },
          DisplayFormat: {
            Formatter: 'DateFormatter',
            Options: {
              Pattern: 'yyyy/MM/dd',
            },
          },
        },
        {
          Name: 'formatColumn-updated_at',
          Scope: {
            ColumnIds: ['updated_at'],
          },
          DisplayFormat: {
            Formatter: 'DateFormatter',
            Options: {
              Pattern: 'MMM do yyyy',
            },
          },
        },
        {
          Name: 'formatColumn-pushed_at',
          Scope: {
            ColumnIds: ['pushed_at'],
          },
          DisplayFormat: {
            Formatter: 'DateFormatter',
            Options: {
              Pattern: 'EEEE',
            },
          },
        },
      ],
    },
  },
};
```

### FAQ

**Can we show only the time portion of a date?**
Yes. Set `Pattern` to a time-only pattern such as `HH:mm:ss` (also available as a wizard preset).

**How do we set a custom date layout?**
Set `DisplayFormat` to `{ Formatter: 'DateFormatter', Options: { Pattern: '…' } }`. Pattern letters follow the [Unicode date field symbols](https://www.adaptabletools.com/docs/handbook-column-formatting-display-format-date/index.md) table linked above.

**Are date presets the same as numeric presets?**
No. Date wizard presets are shortcuts that fill in `Pattern`; there is no `DisplayFormat: 'ShortDate'` style name in state. Numeric columns can use preset names directly in `DisplayFormat`.
