A2oz

What is Date Format in jQuery Datepicker?

Published in jQuery 2 mins read

The jQuery Datepicker allows you to customize the way dates are displayed. This is done through the dateFormat option.

The dateFormat option accepts a string that defines the date format. This string uses special characters to represent different parts of the date, such as the year, month, and day.

Here are some common date formats:

  • "yy-mm-dd": This format displays the date as a year, month, and day, separated by hyphens. For example, "2023-03-15".
  • "mm/dd/yy": This format displays the date as a month, day, and year, separated by slashes. For example, "03/15/2023".
  • "dd.mm.yy": This format displays the date as a day, month, and year, separated by periods. For example, "15.03.2023".
  • "d MM yy": This format displays the date as a day, month (in words), and year. For example, "15 March 2023".

You can use the dateFormat option when initializing the Datepicker:

$( "#datepicker" ).datepicker({
  dateFormat: "yy-mm-dd"
});

This will set the date format to "yy-mm-dd" for the datepicker with the ID "datepicker".

You can also change the date format after the Datepicker has been initialized:

$( "#datepicker" ).datepicker( "option", "dateFormat", "mm/dd/yy" );

This will change the date format to "mm/dd/yy" for the datepicker with the ID "datepicker".

By using the dateFormat option, you can ensure that the dates are displayed in the format that is most suitable for your application.

Related Articles