Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk3 min

Set the Current Date in a Datepicker with JavaScript or jQuery

Use jQuery UI Datepicker’s setDate method for a text field, or assign a native date input a yyyy-mm-dd value. The two controls use different formats and integration rules.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To select today in jQuery UI Datepicker, call datepicker("setDate", new Date()). For a browser-native <input type="date">, assign its value in yyyy-mm-dd form. These are different controls: use jQuery UI on a text input, not on a native date input.

First identify which datepicker you are using

“Datepicker” may mean jQuery UI’s widget attached to a text field, or the picker supplied by the browser and operating system for an HTML date input. The code for setting a date differs between them, as do their value formats.

Control Who provides the picker UI Value format Integration notes
jQuery UI Datepicker on a text input jQuery UI The configured jQuery UI dateFormat; the documented default is mm/dd/yy, where yy is a four-digit year. Requires jQuery UI and its functional CSS. Programmatic updates may not fire a native change event.
Native <input type="date"> The browser and operating system Normalized yyyy-mm-dd, even if the displayed date looks different. Do not attach jQuery UI Datepicker to this input; the two picker interfaces conflict.

Set today in jQuery UI Datepicker

Attach the widget to a text input, then call its setDate method with a JavaScript Date object:

<input id="date" type="text">

<script>
  $("#date").datepicker();
  $("#date").datepicker("setDate", new Date());
</script>

new Date() represents the current date when that code runs. If the datepicker has already been initialized, call only the second line. The jQuery UI API also allows a string in the widget’s active date format, but a Date object avoids manually building that formatted string.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use setDate, not defaultDate, to fill the field

setDate sets the selected date in the widget and its input. The defaultDate option instead controls the date highlighted when the picker first opens while the field is blank. Its default is null, which means today; it is not the documented way to populate the input with today’s date.

Read the selected date back

Use getDate when application code needs the selected value as a JavaScript Date object. It returns the current selected date, or null if there is no selection.

const selectedDate = $("#date").datepicker("getDate");

Set today in a native HTML date input

Assign the input’s value using the normalized yyyy-mm-dd format. The date the user sees can be displayed differently according to browser locale, so do not build the value from the visible presentation.

<input id="date" type="date">

<script>
  const input = document.querySelector("#date");
  input.value = "2026-10-04"; // Example only; generate the intended current date.
</script>

The example is a fixed date, not a production method for “today.” Generate the string at runtime, making sure your application’s intended date semantics—such as local calendar date—match how the date is constructed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose one picker per field

jQuery UI’s documentation says its Datepicker is unsupported on <input type="date"> because it conflicts with the browser’s native picker. Use a text input for the jQuery UI widget, or keep type="date" and set its value directly.

Handle formatting, events, and dependencies

  • jQuery UI string formats: The documented default is mm/dd/yy; in jQuery UI’s format tokens, yy means a four-digit year. If passing a string to setDate, match the active dateFormat. The API also shows yy-mm-dd as an example format.
  • Native input values: The value contract is yyyy-mm-dd, regardless of the locale-dependent format rendered in the control.
  • Change handling: jQuery UI notes that it updates the element’s value programmatically, so a native change event may not fire. If other code must react to the update, call that application update path explicitly or verify the event behavior in your integration; do not assume setDate triggers every handler.
  • jQuery UI setup: The widget requires its functional CSS. Its documented dependencies include UI Core; Effects Core is optional.
  • Native appearance: The browser and operating system determine how the native picker looks. Its normalized value is more consistent than its visual presentation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.