$(() => {
const now = new Date();
$('#date').dxDateBox({
type: 'date',
value: now,
inputAttr: { 'aria-label': 'Date' },
});
$('#time').dxDateBox({
type: 'time',
value: now,
inputAttr: { 'aria-label': 'Time' },
});
$('#date-time').dxDateBox({
type: 'datetime',
value: now,
inputAttr: { 'aria-label': 'Date Time' },
});
$('#custom').dxDateBox({
displayFormat: 'EEEE, MMM dd',
value: now,
inputAttr: { 'aria-label': 'Custom Date' },
});
$('#date-by-picker').dxDateBox({
pickerType: 'rollers',
value: now,
inputAttr: { 'aria-label': 'Picker Date' },
});
$('#disabled').dxDateBox({
type: 'datetime',
disabled: true,
value: now,
inputAttr: { 'aria-label': 'Disabled' },
});
$('#disabledDates').dxDateBox({
type: 'date',
pickerType: 'calendar',
value: new Date(2017, 0, 3),
disabledDates: federalHolidays,
inputAttr: { 'aria-label': 'Disabled' },
});
$('#clear').dxDateBox({
type: 'time',
showClearButton: true,
value: new Date(2015, 11, 1, 6),
inputAttr: { 'aria-label': 'Clear Date' },
});
const startDate = new Date(1981, 3, 27);
$('#birthday').dxDateBox({
applyValueMode: 'useButtons',
value: startDate,
max: new Date(),
min: new Date(1900, 0, 1),
inputAttr: { 'aria-label': 'Birth Date' },
onValueChanged(data) {
dateDiff(new Date(data.value));
},
});
function dateDiff(date) {
const diffInDay = Math.floor(Math.abs((new Date() - date) / (24 * 60 * 60 * 1000)));
return $('#age').text(`${diffInDay} days`);
}
dateDiff(startDate);
});
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<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=5.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/24.1.7/css/dx.light.css" />
<script src="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">
<div class="dx-fieldset">
<div class="dx-field">
<div class="dx-field-label">Date</div>
<div class="dx-field-value">
<div id="date"></div>
</div>
</div>
<div class="dx-field">
<div class="dx-field-label">Time</div>
<div class="dx-field-value">
<div id="time"></div>
</div>
</div>
<div class="dx-field">
<div class="dx-field-label">Date and time</div>
<div class="dx-field-value">
<div id="date-time"></div>
</div>
</div>
<div class="dx-field">
<div class="dx-field-label">Custom format</div>
<div class="dx-field-value">
<div id="custom"></div>
</div>
</div>
<div class="dx-field">
<div class="dx-field-label">Date picker</div>
<div class="dx-field-value">
<div id="date-by-picker"></div>
</div>
</div>
<div class="dx-field">
<div class="dx-field-label">Clear button</div>
<div class="dx-field-value">
<div id="clear"></div>
</div>
</div>
<div class="dx-field">
<div class="dx-field-label">Disabled</div>
<div class="dx-field-value">
<div id="disabled"></div>
</div>
</div>
<div class="dx-field">
<div class="dx-field-label">Disable certain dates</div>
<div class="dx-field-value">
<div id="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 id="birthday"></div>
</div>
</div>
<div class="dx-field">
<div class="dx-field-value"> Your age is <div id="age"></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),
];