Date cell type
Display, format, sort, and filter dates correctly by using the date cell type.
Overview
The date cell type lets you treat cell values as dates: format how they are displayed, validate input, and use an interactive date picker in the editor. Handsontable supports two configurations: the object-style configuration using the native Intl.DateTimeFormat API (recommended), and a string-style configuration using Moment.js (deprecated).
Date cell type demo
In the following demo, multiple columns use the date cell type with different formatting styles:
- Product date: Date with short style formatting
- Payment date: Customized date formatting
- Registration date: Customized date formatting with weekday, month, day, year
import Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';
// Register all Handsontable's modules.registerAllModules();
const container = document.querySelector('#example1');const dropdown = document.querySelector('#localeDropdown');const trigger = document.querySelector('#localeTrigger');const menu = document.querySelector('#localeMenu');const label = document.querySelector('#localeLabel');32 collapsed lines
const data = [ { car: 'Mercedes A 160', product_date: '2002-06-15', payment_date: '2002-05-20', registration_date: '2002-07-01', }, { car: 'Citroën C4 Coupe', product_date: '2007-03-22', payment_date: '2007-02-28', registration_date: '2007-04-10', }, { car: 'Audi A4 Avant', product_date: '2011-09-08', payment_date: '2011-08-15', registration_date: '2011-09-20', }, { car: 'Opel Astra', product_date: '2012-01-30', payment_date: '2012-01-10', registration_date: '2012-02-14', }, { car: 'BMW 320i Coupe', product_date: '2004-11-12', payment_date: '2004-10-20', registration_date: '2004-12-01', },];
const hot = new Handsontable(container, { data, colHeaders: ['Car', 'Product date', 'Payment date', 'Registration date'],32 collapsed lines
columns: [ { type: 'text', data: 'car', }, { type: 'intl-date', data: 'product_date', dateFormat: { dateStyle: 'short', }, }, { type: 'intl-date', data: 'payment_date', dateFormat: { month: 'long', day: 'numeric', year: 'numeric', }, }, { type: 'intl-date', data: 'registration_date', dateFormat: { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', }, }, ], columnSorting: true, filters: true, dropdownMenu: true, height: 'auto', licenseKey: 'non-commercial-and-evaluation', autoWrapRow: true, autoWrapCol: true,});
// Handle dropdown toggletrigger.addEventListener('click', () => { const isOpen = !menu.hidden;
menu.hidden = isOpen; trigger.setAttribute('aria-expanded', String(!isOpen));});
// Handle locale selectionmenu.addEventListener('click', (e) => { const item = e.target.closest('li[data-value]');
if (item) { label.textContent = item.textContent.trim(); menu.querySelectorAll('li').forEach((li) => li.setAttribute('aria-selected', 'false')); item.setAttribute('aria-selected', 'true'); menu.hidden = true; trigger.setAttribute('aria-expanded', 'false'); hot.updateSettings({ locale: item.dataset.value }); }});
// Close dropdown when clicking outsidedocument.addEventListener('click', (e) => { if (!dropdown.contains(e.target)) { menu.hidden = true; trigger.setAttribute('aria-expanded', 'false'); }});
// Close dropdown on Escape keydocument.addEventListener('keydown', (e) => { if (e.key === 'Escape' && !menu.hidden) { menu.hidden = true; trigger.setAttribute('aria-expanded', 'false'); trigger.focus(); }});import Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';
// Register all Handsontable's modules.registerAllModules();
const container = document.querySelector('#example1')!;const dropdown = document.querySelector('#localeDropdown')!;const trigger = document.querySelector('#localeTrigger')!;const menu = document.querySelector('#localeMenu')!;const label = document.querySelector('#localeLabel')!;32 collapsed lines
const data = [ { car: 'Mercedes A 160', product_date: '2002-06-15', payment_date: '2002-05-20', registration_date: '2002-07-01', }, { car: 'Citroën C4 Coupe', product_date: '2007-03-22', payment_date: '2007-02-28', registration_date: '2007-04-10', }, { car: 'Audi A4 Avant', product_date: '2011-09-08', payment_date: '2011-08-15', registration_date: '2011-09-20', }, { car: 'Opel Astra', product_date: '2012-01-30', payment_date: '2012-01-10', registration_date: '2012-02-14', }, { car: 'BMW 320i Coupe', product_date: '2004-11-12', payment_date: '2004-10-20', registration_date: '2004-12-01', },];
const hot = new Handsontable(container, { data, colHeaders: ['Car', 'Product date', 'Payment date', 'Registration date'],32 collapsed lines
columns: [ { type: 'text', data: 'car', }, { type: 'intl-date', data: 'product_date', dateFormat: { dateStyle: 'short', }, }, { type: 'intl-date', data: 'payment_date', dateFormat: { month: 'long', day: 'numeric', year: 'numeric', }, }, { type: 'intl-date', data: 'registration_date', dateFormat: { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', }, }, ], columnSorting: true, filters: true, dropdownMenu: true, height: 'auto', licenseKey: 'non-commercial-and-evaluation', autoWrapRow: true, autoWrapCol: true,});
// Handle dropdown toggletrigger.addEventListener('click', () => { const isOpen = !menu.hidden;
menu.hidden = isOpen; trigger.setAttribute('aria-expanded', String(!isOpen));});
// Handle locale selectionmenu.addEventListener('click', (e) => { const item = (e.target as HTMLElement).closest('li[data-value]') as HTMLLIElement | null;
if (item) { label.textContent = item.textContent!.trim(); menu.querySelectorAll('li').forEach((li) => li.setAttribute('aria-selected', 'false')); item.setAttribute('aria-selected', 'true'); menu.hidden = true; trigger.setAttribute('aria-expanded', 'false'); hot.updateSettings({ locale: item.dataset.value }); }});
// Close dropdown when clicking outsidedocument.addEventListener('click', (e) => { if (!dropdown.contains(e.target as Node)) { menu.hidden = true; trigger.setAttribute('aria-expanded', 'false'); }});
// Close dropdown on Escape keydocument.addEventListener('keydown', (e) => { if (e.key === 'Escape' && !menu.hidden) { menu.hidden = true; trigger.setAttribute('aria-expanded', 'false'); trigger.focus(); }});<div class="example-controls-container"> <div class="controls"> <div class="theme-dropdown" id="localeDropdown"> <button class="theme-dropdown-trigger" id="localeTrigger" type="button" aria-haspopup="listbox" aria-expanded="false"> <span id="localeLabel">English (United States)</span> <svg class="theme-dropdown-chevron" aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9l6 6l6 -6"/></svg> </button> <ul class="theme-dropdown-menu" id="localeMenu" role="listbox" hidden> <li role="option" data-value="ar-AR">Arabic (Global)</li> <li role="option" data-value="cs-CZ">Czech (Czechia)</li> <li role="option" data-value="de-CH">German (Switzerland)</li> <li role="option" data-value="de-DE">German (Germany)</li> <li role="option" data-value="en-US" aria-selected="true">English (United States)</li> <li role="option" data-value="es-MX">Spanish (Mexico)</li> <li role="option" data-value="fa-IR">Persian (Iran)</li> <li role="option" data-value="fr-FR">French (France)</li> <li role="option" data-value="hr-HR">Croatian (Croatia)</li> <li role="option" data-value="it-IT">Italian (Italy)</li> <li role="option" data-value="ja-JP">Japanese (Japan)</li> <li role="option" data-value="ko-KR">Korean (Korea)</li> <li role="option" data-value="lv-LV">Latvian (Latvia)</li> <li role="option" data-value="nb-NO">Norwegian Bokmal (Norway)</li> <li role="option" data-value="nl-NL">Dutch (Netherlands)</li> <li role="option" data-value="pl-PL">Polish (Poland)</li> <li role="option" data-value="pt-BR">Portuguese (Brazil)</li> <li role="option" data-value="ru-RU">Russian (Russia)</li> <li role="option" data-value="sr-SP">Serbian Latin (Serbia)</li> <li role="option" data-value="zh-CN">Chinese (Simplified, China)</li> <li role="option" data-value="zh-TW">Chinese (Traditional, Taiwan)</li> </ul> </div> </div></div>
<div id="example1"></div>Use the date cell type
Use the object-style configuration by setting the type option to 'intl-date' and dateFormat to an object (recommended). The locale is controlled via the locale option.
// set the date cell type for the entire grid (Intl, recommended)type: 'intl-date',locale: 'en-US',dateFormat: { year: 'numeric', month: '2-digit', day: '2-digit'},
// set the date cell type for a single columncolumns: [ { type: 'intl-date', locale: 'en-US', dateFormat: { dateStyle: 'short' } }],
// set the date cell type for a single cellcell: [ { row: 0, col: 2, type: 'intl-date', locale: 'en-US', dateFormat: { dateStyle: 'medium' } }],For intl-date cells, source data must be in ISO 8601 date format (YYYY-MM-DD) for dates to work correctly. The dateFormat object only affects how dates are displayed; sorting and filtering rely on the underlying ISO value.
Format dates
To control how dates are displayed in cell renderers, use the dateFormat option.
Since Handsontable 17.0, the recommended approach is the object form of dateFormat with the intl-date cell type, which uses the native Intl.DateTimeFormat API. The locale is controlled separately via the locale option.
Using Intl.DateTimeFormat (recommended)
The dateFormat option accepts all properties of Intl.DateTimeFormat options. Use it with type: 'intl-date'.
columns: [ { type: 'intl-date', locale: 'en-US', dateFormat: { year: 'numeric', month: '2-digit', day: '2-digit' } }, { type: 'intl-date', locale: 'de-DE', dateFormat: { dateStyle: 'long' } }]Date-specific options
Style shortcuts:
| Property | Possible values | Description |
|---|---|---|
dateStyle | 'full', 'long', 'medium', 'short' | Date formatting style (weekday, day, month, year, era) |
timeStyle | 'full', 'long', 'medium', 'short' | Time part style (hour, minute, second, timeZoneName); use for date+time |
Date-time component options:
| Property | Possible values | Description |
|---|---|---|
weekday | 'long', 'short', 'narrow' | Weekday representation |
era | 'long', 'short', 'narrow' | Era representation |
year | 'numeric', '2-digit' | Year representation |
month | 'numeric', '2-digit', 'long', 'short', 'narrow' | Month representation |
day | 'numeric', '2-digit' | Day representation |
dayPeriod | 'narrow', 'short', 'long' | Day period (e.g. “am”) |
hour | 'numeric', '2-digit' | Hour (if time included) |
minute | 'numeric', '2-digit' | Minute |
second | 'numeric', '2-digit' | Second |
fractionalSecondDigits | 1, 2, 3 | Fraction-of-second digits |
timeZoneName | 'long', 'short', 'shortOffset', 'longOffset', 'shortGeneric', 'longGeneric' | Time zone display |
Locale and other options:
| Property | Possible values | Description |
|---|---|---|
localeMatcher | 'best fit' (default), 'lookup' | Locale matching algorithm |
calendar | 'chinese', 'gregory', 'persian', etc. | Calendar to use |
numberingSystem | 'latn', 'arab', 'hans', etc. | Numbering system |
timeZone | IANA time zone (e.g. 'UTC', 'America/New_York') | Time zone for formatting |
hour12 | true, false | 12-hour vs 24-hour time |
hourCycle | 'h11', 'h12', 'h23', 'h24' | Hour cycle |
formatMatcher | 'basic', 'best fit' (default) | Format matching algorithm |
For a complete reference, see the dateFormat API documentation or MDN: Intl.DateTimeFormat.
Using string format with Moment.js (deprecated)
The date cell type with a string dateFormat is still supported but will be removed in next major release.
Deprecated options:
| Option | Description | Replacement |
|---|---|---|
dateFormat (string) | Moment.js format (e.g. 'DD/MM/YYYY') | Use intl-date with dateFormat object (see above) |
correctFormat | Auto-correct entered date to match format | May be handled by valueParser and/or valueSetter options |
datePickerConfig | Pikaday options for the date picker | intl-date uses a native date picker; no direct equivalent |
Migration example:
// Before (deprecated)columns: [{ type: 'date', dateFormat: 'YYYY-MM-DD',}]
// After (recommended)columns: [{ type: 'intl-date', locale: 'en-US', dateFormat: { year: 'numeric', month: '2-digit', day: '2-digit', }}]Editor behavior
The dateFormat option controls how dates are displayed in the cell. The editor (date picker or text input) may show the value in a normalized form; for intl-date, the underlying value remains in ISO 8601 format.
Related articles
Related guides
Configuration options
Core methods
Hooks