- 1 year ago 487
Javascript Question

Change the date format to yyyy-mm-dd in Datepicker

I am using Datepicker for my HTML field .
The HTML code is :

<input type="text" id="from-datepicker"/>

The Jquery code to set and get the date picker fields is :

$("#from-datepicker").datepicker({ dateFormat: 'yy-mm-dd'});
$("#from-datepicker").on("change", function () {
var fromdate = $(this).val();

This code, however, displays the field in
Can someone tell me where am I going wrong ?

My imported CDNs are :

<script type="text/javascript"

<link rel="stylesheet" type="text/css"

Thanks in advance.

Answer Source

Yes, change dateFormat to just format and you need 4 sets of 'y's

Sample code:

<script   src=""   integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo="   crossorigin="anonymous"></script>
<link href="" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script type="text/javascript" src=""></script>
<link rel="stylesheet" type="text/css" href="">
$( document ).ready(function() {
        format: 'yyyy-mm-dd'
    $("#from-datepicker").on("change", function () {
        var fromdate = $(this).val();
<input type="text" id="from-datepicker"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download