0

I'm using the jQuery date selector in an app I'm writing. However the date format isn't correct to the calendar I'm appending it to and when I try to change the format with the functions defined in the API documentation, however none of them have worked.

What I've tried: 1.

$(".selector").datepicker({
        altFormat: "yy-mm-dd"
    });

Does not produce error but simply doesn't work

2.

$("#datepicker").formatDate("yy-mm-dd");

Produces error:

$(...).formatDate is not a function

Thanks

tzcoding
  • 69
  • 6

3 Answers3

0

Can you try this.

$("#datepicker").datepicker("option", "dateFormat", "yy-mm-dd");
David Buck
  • 3,752
  • 35
  • 31
  • 35
0

I think you requirement is to use dateFormat not altFormat. altFormat has different purpose that you want to use.

"altFormat allows one date format to be shown to the user for selection purposes, while a different format is actually sent behind the scenes." https://api.jqueryui.com/datepicker/#option-altFormat

$(".selector").datepicker({
  dateFormat: "yy-mm-dd"
});
  • didn't work somehow, i have this code `$(function() { $('#datepicker').datepicker({ dateFormat: 'yy-mm-dd', showButtonPanel: true, changeMonth: true, changeYear: true, defaultDate: new Date() }); });` which doesn't work either – tzcoding Apr 26 '20 at 11:00
  • The code you provided worked when I test it. There could be javascript error before running this code to prevent it to run. Can you please see the javascript error. – Mahesh Shrestha Apr 26 '20 at 11:09
  • `$(...).datepicker is not a function` all of a sudden – tzcoding Apr 26 '20 at 11:12
  • This could be resulted because of many reasons. probable reasons could be 1. required library for datepicker is not loaded properly. 2. conflict please refer https://stackoverflow.com/questions/1212696/jquery-ui-datepicker-datepicker-is-not-a-function if you can find the problem. – Mahesh Shrestha Apr 26 '20 at 11:23
0

Fixed it. I hadn't linked a necessary script

tzcoding
  • 69
  • 6