QuickNav

Options

altField
altFormat
appendText
autoSize
buttonImage
buttonImageOnly
buttonText
calculateWeek
changeMonth
changeYear
closeText
constrainInput
currentText
dateFormat
dayNames
dayNamesMin
dayNamesShort
defaultDate
duration
firstDay
gotoCurrent
hideIfNoPrevNext
isRTL
maxDate
minDate
monthNames
monthNamesShort
navigationAsDateFormat
nextText
numberOfMonths
prevText
selectOtherMonths
shortYearCutoff
showAnim
showButtonPanel
showCurrentAtPos
showMonthAfterYear
showOn
showOptions
showOtherMonths
showWeek
stepMonths
weekHeader
yearRange
yearSuffix
beforeShow
beforeShowDay
onChangeMonthYear
onClose
onSelect

Methods

destroy
dialog
isDisabled
hide
show
refresh
getDate
setDate

Events

Datepicker Widgetversion added: 1.0

Description: Select a date from a popup or inline calendar

Options

altFieldType: Selector or jQuery or Element

Default: ""
An input element that is to be updated with the selected date from the datepicker. Use the altFormat option to change the format of the date within this field. Leave as blank for no alternate field.

altFormatType: String

Default: ""
The dateFormat to be used for the altField option. This allows one date format to be shown to the user for selection purposes, while a different format is actually sent behind the scenes. For a full list of the possible formats see the [[UI/Datepicker/formatDate|formatDate]] function

appendTextType: String

Default: ""
The text to display after each date field, e.g., to show the required format.

autoSizeType: Boolean

Default: false
Set to true to automatically resize the input field to accommodate dates in the current dateFormat.

beforeShowType: Function( Element input, Object inst )

Default: null
A function that takes an input field and current datepicker instance and returns an options object to update the datepicker with. It is called just before the datepicker is displayed.

beforeShowDayType: Function( Date date )

Default: null
A function takes a date as a parameter and must return an array with [0] equal to true/false indicating whether or not this date is selectable, [1] equal to a CSS class name or "" for the default presentation, and [2] an optional popup tooltip for this date. It is called for each day in the datepicker before it is displayed.

buttonImageType: String

Default: ""
The URL for the popup button image. If set, the buttonText option becomes the alt value and is not directly displayed.

buttonImageOnlyType: Boolean

Default: false
Whether the button image should be rendered by itself instead of inside a button element.

buttonTextType: String

Default: "..."
The text to display on the trigger button. Use in conjunction with the showOn option set to "button" or "both".

calculateWeekType: Function()

Default: jQuery.datepicker.iso8601Week
A function to calculate the week of the year for a given date. The default implementation uses the ISO 8601 definition: weeks start on a Monday; the first week of the year contains the first Thursday of the year.

changeMonthType: Boolean

Default: false
Whether the month should be rendered as a dropdown instead of text.

changeYearType: Boolean

Default: false
Whether the year should be rendered as a dropdown instead of text. Use the yearRange option to control which years are made available for selection.

closeTextType: String

Default: "Done"
The text to display for the close link. Use the showButtonPanel option to display this button.

constrainInputType: Boolean

Default: true
When true, entry in the input field is constrained to those characters allowed by the current dateFormat option.

currentTextType: String

Default: "Today"
The text to display for the current day link. Use the showButtonPanel option to display this button.

dateFormatType: String

Default: "mm/dd/yy"
The format for parsed and displayed dates. For a full list of the possible formats see the [[UI/Datepicker/formatDate|formatDate]] function.

dayNamesType: Array

Default: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]
The list of long day names, starting from Sunday, for use as requested via the dateFormat option.

dayNamesMinType: Array

Default: [ "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" ]
The list of minimised day names, starting from Sunday, for use as column headers within the datepicker.

dayNamesShortType: Array

Default: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]
The list of abbreviated day names, starting from Sunday, for use as requested via the dateFormat option.

defaultDateType: Date or Number or String

Default: null
Set the date to highlight on first opening if the field is blank. Specify either an actual date via a Date object or as a string in the current [[UI/Datepicker#option-dateFormat|dateFormat]], or a number of days from today (e.g. +7) or a string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '+1m +7d'), or null for today.
Multiple types supported:
  • Date: A date object containing the default date.
  • Number: A number of days from today. For example 2 represents two days from today and -1 represents yesterday.
  • String: A string in the format defined by the dateFormat option, or a relative date. Relative dates must contain value and period pairs; valid periods are "y" for years, "m" for months, "w" for weeks, and "d" for days. For example, "+1m +7d" represents one month and seven days from today.

durationType: or String

Default: "normal"
Control the speed at which the datepicker appears, it may be a time in milliseconds or a string representing one of the three predefined speeds ("slow", "normal", "fast").

firstDayType: Integer

Default: 0
Set the first day of the week: Sunday is 0, Monday is 1, etc.

gotoCurrentType: Boolean

Default: false
When true, the current day link moves to the currently selected date instead of today.

hideIfNoPrevNextType: Boolean

Default: false
Normally the previous and next links are disabled when not applicable (see the minDate and maxDate options). You can hide them altogether by setting this attribute to true.

isRTLType: Boolean

Default: false
Whether the current language is drawn from right to left.

maxDateType: Date or Number or String

Default: null
The maximum selectable date. When set to null, there is no maximum.
Multiple types supported:
  • Date: A date object containing the maximum date.
  • Number: A number of days from today. For example 2 represents two days from today and -1 represents yesterday.
  • String: A string in the format defined by the dateFormat option, or a relative date. Relative dates must contain value and period pairs; valid periods are "y" for years, "m" for months, "w" for weeks, and "d" for days. For example, "+1m +7d" represents one month and seven days from today.

minDateType: Date or Number or String

Default: null
The minimum selectable date. When set to null, there is no minimum.
Multiple types supported:
  • Date: A date object containing the minimum date.
  • Number: A number of days from today. For example 2 represents two days from today and -1 represents yesterday.
  • String: A string in the format defined by the dateFormat option, or a relative date. Relative dates must contain value and period pairs; valid periods are "y" for years, "m" for months, "w" for weeks, and "d" for days. For example, "+1m +7d" represents one month and seven days from today.

monthNamesType: Array

Default: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]
The list of full month names, for use as requested via the dateFormat option.

monthNamesShortType: Array

Default: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
The list of abbreviated month names, as used in the month header on each datepicker and as requested via the dateFormat option.

navigationAsDateFormatType: Boolean

Default: false
Whether the prevText and nextText options should be parsed as dates by the [[UI/Datepicker/formatDate|formatDate]] function, allowing them to display the target month names for example.

nextTextType: String

Default: "Next"
The text to display for the next month link. With the standard ThemeRoller styling, this value is replaced by an icon.

numberOfMonthsType: Number or Array

Default: 1
The number of months to show at once.
Multiple types supported:
  • Number: The number of months to display in a single row.
  • Array: An array defining the number of rows and columns to display.

onChangeMonthYearType: Function( Integer year, Integer month, Object inst )

Default: null
Called when the datepicker moves to a new month and/or year. The function receives the selected year, month (1-12), and the datepicker instance as parameters. this refers to the associated input field.

onCloseType: Function( String dateText, Object inst )

Default: null
Called when the datepicker is closed, whether or not a date is selected. The function receives the selected date as text ("" if none) and the datepicker instance as parameters. this refers to the associated input field.

onSelectType: Function( String dateText, Object inst )

Default: null
Called when the datepicker is selected. The function receives the selected date as text and the datepicker instance as parameters. this refers to the associated input field.

prevTextType: String

Default: "Prev"
The text to display for the previous month link. With the standard ThemeRoller styling, this value is replaced by an icon.

selectOtherMonthsType: Boolean

Default: false
Whether days in other months shown before or after the current month are selectable. This only applies if the showOtherMonths option is set to true.

shortYearCutoffType: Number or String

Default: "+10"
The cutoff year for determining the century for a date (used in conjunction with [[UI/Datepicker#option-dateFormat|dateFormat]] 'y'). Any dates entered with a year value less than or equal to the cutoff year are considered to be in the current century, while those greater than it are deemed to be in the previous century.
Multiple types supported:
  • Number: A value between 0 and 99 indicating the cutoff year.
  • String: A relative number of years from the current year, e.g., "+3" or "-5".

showAnimType: String

Default: "show"
The name of the animation used to show and hide the datepicker. Use "show" (the default), "slideDown", "fadeIn", any of the jQuery UI effects. Set to an empty string to disable animation.

showButtonPanelType: Boolean

Default: false
Whether to show the button panel.

showCurrentAtPosType: Number

Default: 0
When displaying multiple months via the numberOfMonths option, the showCurrentAtPos option defines which position to display the current month in.

showMonthAfterYearType: Boolean

Default: false
Whether to show the month after the year in the header.

showOnType: String

Default: "focus"
When the datepicker should appear. The datepicker can appear when the field receives focus ("focus"), when a button is clicked ("button"), or when either event occurs ("both").

showOptionsType: Object

Default: {}
If using one of the jQuery UI effects for the showAnim option, you can provide additional settings for that animation via this option.

showOtherMonthsType: Boolean

Default: false
Whether to display dates in other months (non-selectable) at the start or end of the current month. To make these days selectable use the selectOtherMonths option.

showWeekType: Boolean

Default: false
When true, a column is added to show the week of the year. The calculateWeek option determines how the week of the year is calculated. You may also want to change the firstDay option.

stepMonthsType: Number

Default: 1
Set how many months to move when clicking the previous/next links.

weekHeaderType: String

Default: "Wk"
The text to display for the week of the year column heading. Use the showWeek option to display this column.

yearRangeType: String

Default: "c-10:c+10"
The range of years displayed in the year drop-down: either relative to today's year ("-nn:+nn"), relative to the currently selected year ("c-nn:c+nn"), absolute ("nnnn:nnnn"), or combinations of these formats ("nnnn:-nn"). Note that this option only affects what appears in the drop-down, to restrict which dates may be selected use the minDate and/or maxDate options.

yearSuffixType: String

Default: ""
Additional text to display after the year in the month headers.

Methods

destroy()

Removes the datepicker functionality completely. This will return the element back to its pre-init state.

dialog( date [, onSelect ] [, settings ] [, pos ] )

Opens the datepicker in a dialog box.
  • date
    Type: String or Date
    The initial date.
  • onSelect
    Type: Function()
    A callback function when a date is selected. The function receives the date text and date picker instance as parameters.
  • settings
    Type: Options
    The new settings for the date picker.
  • pos
    The position of the top/left of the dialog as [x, y] or a MouseEvent that contains the coordinates. If not specified the dialog is centered on the screen.

getDate() Returns: Date

Returns the current date for the datepicker or null if no date has been selected.

hide()

Close a previously opened date picker.

isDisabled() Returns: Boolean

Determine whether a date picker has been disabled.

refresh()

Redraw the date picker, after having made some external modifications.

setDate( date )

Sets the date for the datepicker. The new date may be a Date object or a string in the current date format (e.g., "01/26/2009"), a number of days from today (e.g., +7) or a string of values and periods ("y" for years, "m" for months, "w" for weeks, "d" for days, e.g., "+1m +7d"), or null to clear the selected date.
  • date
    Type: Date
    The new date.

show()

Open the date picker. If the datepicker is attached to an input, the input must be visible for the datepicker to be shown.

The jQuery UI Datepicker is a highly configurable plugin that adds datepicker functionality to your pages. You can customize the date format and language, restrict the selectable date ranges and add in buttons and other navigation options easily.

By default, the datepicker calendar opens in a small overlay when the associated text field gains focus. For an inline calendar, simply attach the datepicker to a div or span.

Keyboard interaction

While the datepicker is open, the following key commands are available:

  • PAGE UP: Move to the previous month.
  • PAGE DOWN: Move to the next month.
  • CTRL+PAGE UP: Move to the previous year.
  • CTRL+PAGE DOWN: Move to the next year.
  • CTRL+HOME: Move to the current month. Open the datepicker if closed.
  • CTRL+LEFT: Move to the previous day.
  • CTRL+RIGHT: Move to the next day.
  • CTRL+UP: Move to the previous week.
  • CTRL+DOWN: Move the next week.
  • ENTER: Select the focused date.
  • CTRL+END: Close the datepicker and erase the date.
  • ESCAPE: Close the datepicker without selection.

Utility functions

  • $.datepicker.setDefaults( settings ) - Set settings for all datepicker instances.
  • $.datepicker.formatDate( format, date, settings ) - Format a date into a string value with a specified format.
  • $.datepicker.parseDate( format, value, settings ) - Extract a date from a string value with a specified format.
  • $.datepicker.iso8601Week( date ) - Determine the week of the year for a given date: 1 to 53.
  • $.datepicker.noWeekends - Set as beforeShowDay function to prevent selection of weekends.

Localization

Datepicker provides support for localizing its content to cater for different languages and date formats. Each localization is contained within its own file with the language code appended to the name, e.g., jquery.ui.datepicker-fr.js for French. The desired localization file should be included after the main datepicker code. Each localization file adds its settings to the set of available localizations and automatically applies them as defaults for all instances.

The $.datepicker.regional attribute holds an array of localizations, indexed by language code, with "" referring to the default (English). Each entry is an object with the following attributes: closeText, prevText, nextText, currentText, monthNames, monthNamesShort, dayNames, dayNamesShort, dayNamesMin, weekHeader, dateFormat, firstDay, isRTL, showMonthAfterYear, and yearSuffix.

You can restore the default localizations with:

$.datepicker.setDefaults( $.datepicker.regional[ "" ] );

And can then override an individual datepicker for a specific locale:

$( selector ).datepicker( $.datepicker.regional[ "fr" ] );

Additional Notes:

  • This widget requires some functional CSS, otherwise it won't work. If you build a custom theme, use the widget's specific CSS file as a starting point.

Example:

A simple jQuery UI Datepicker.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>datepicker demo</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css">
    <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
</head>
<body>
 
<div id="datepicker"></div>
 
<script>
$( "#datepicker" ).datepicker();
</script>
 
</body>
</html>

Demo: