DevExtreme v23.1 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.
Date Box

Overview

The DateBox editor helps users enter or modify date and time values. This demo illustrates the following DateBox properties:

  • value
    A value the DateBox displays.

  • type
    Specifies whether the DateBox allows users to select one of the following types:

    • "date"
      Users can select the date from the calendar, or they can type in their own date value (in the required format).

    • "time"
      Users can select a time from a range between 12:00 AM and 11:30 PM at 30-minute intervals, or they can type in their own time value (in the required format). Specify the interval property to set the time interval.

    • "datetime"
      Users can select the date from the calendar and the time from the spin and dropdown editors. They can also choose the Today button.

  • displayFormat
    A date/time display format. You can use one of the predefined formats or specify a custom format. This demo illustrates the latter.

  • pickerType
    Specifies the type of UI used to select a date or time. This demo shows how to change a calendar to a roller date picker.

  • showClearButton
    Specifies whether to display the button that clears the DateBox value.

  • disabled
    Specifies whether the DateBox responds to user interaction.

  • disabledDates
    Dates that are not available for selection.

  • applyValueMode
    Defines whether the selected value applies instantly or after a user clicks the Apply button.

To get started with the DevExtreme DateBox component, refer to the following tutorial for step-by-step instructions: Getting Started with DateBox.

Backend API
Copy to CodePen
Apply
Reset
const DemoApp = angular.module('DemoApp', ['dx']); DemoApp.controller('DemoController', ($scope) => { const now = new Date(); $scope.dateBox = { dateFormat: { type: 'date', value: now, inputAttr: { 'aria-label': 'Date' }, }, timeFormat: { type: 'time', value: now, inputAttr: { 'aria-label': 'Time' }, }, dateTimeFormat: { type: 'datetime', value: now, inputAttr: { 'aria-label': 'Date and time' }, }, customFormat: { displayFormat: 'EEEE, MMM dd', value: now, inputAttr: { 'aria-label': 'Custom format' }, }, dateByPicker: { pickerType: 'rollers', value: now, inputAttr: { 'aria-label': 'Date picker' }, }, disabled: { type: 'datetime', disabled: true, value: now, inputAttr: { 'aria-label': 'Disabled Date and time' }, }, disabledDates: { type: 'date', pickerType: 'calendar', value: new Date(2017, 0, 3), disabledDates: federalHolidays, inputAttr: { 'aria-label': 'Disabled certain dates' }, }, clear: { type: 'time', showClearButton: true, value: new Date(2015, 11, 1, 6), inputAttr: { 'aria-label': 'Clear button' }, }, eventOptions: { applyValueMode: 'useButtons', value: new Date(1981, 3, 27), max: new Date(), min: new Date(1900, 0, 1), inputAttr: { 'aria-label': 'Set Birthday' }, bindingOptions: { value: 'dateBox.eventOptions.value', }, diffInDay() { return `${Math.floor(Math.abs((new Date() - $scope.dateBox.eventOptions.value) / (24 * 60 * 60 * 1000)))} days`; }, }, }; });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/23.1.5/css/dx.light.css" /> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script> <script>window.angular || document.write(decodeURIComponent('%3Cscript src="js/angular.min.js"%3E%3C/script%3E'))</script> <script src="https://cdn3.devexpress.com/jslib/23.1.5/js/dx.all.js"></script> <script src="data.js"></script> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container" ng-app="DemoApp" ng-controller="DemoController"> <div class="dx-fieldset"> <div class="dx-field"> <div class="dx-field-label">Date</div> <div class="dx-field-value"> <div dx-date-box="dateBox.dateFormat"></div> </div> </div> <div class="dx-field"> <div class="dx-field-label">Time</div> <div class="dx-field-value"> <div dx-date-box="dateBox.timeFormat"></div> </div> </div> <div class="dx-field"> <div class="dx-field-label">Date and time</div> <div class="dx-field-value"> <div dx-date-box="dateBox.dateTimeFormat"></div> </div> </div> <div class="dx-field"> <div class="dx-field-label">Custom format</div> <div class="dx-field-value"> <div dx-date-box="dateBox.customFormat"></div> </div> </div> <div class="dx-field"> <div class="dx-field-label">Date picker</div> <div class="dx-field-value"> <div dx-date-box="dateBox.dateByPicker"></div> </div> </div> <div class="dx-field"> <div class="dx-field-label">Clear button</div> <div class="dx-field-value"> <div dx-date-box="dateBox.clear"></div> </div> </div> <div class="dx-field"> <div class="dx-field-label">Disabled</div> <div class="dx-field-value"> <div dx-date-box="dateBox.disabled"></div> </div> </div> <div class="dx-field"> <div class="dx-field-label">Disable certain dates</div> <div class="dx-field-value"> <div dx-date-box="dateBox.disabledDates"></div> </div> </div> </div> <div class="dx-fieldset"> <div class="dx-fieldset-header">Event Handling</div> <div class="dx-field"> <div class="dx-field-label">Set Birthday</div> <div class="dx-field-value"> <div dx-date-box="dateBox.eventOptions"></div> </div> </div> <div class="dx-field"> <div class="dx-field-value"> Your age is <div id="age">{{dateBox.eventOptions.diffInDay()}}</div> </div> </div> </div> </div> </body> </html>
#age { display: inline-block; }
const federalHolidays = [ new Date(2017, 0, 1), new Date(2017, 0, 2), new Date(2017, 0, 16), new Date(2017, 1, 20), new Date(2017, 4, 29), new Date(2017, 6, 4), new Date(2017, 8, 4), new Date(2017, 9, 9), new Date(2017, 10, 11), new Date(2017, 10, 23), new Date(2017, 11, 25), ];