Why date format is not changed in datepicker?

334
August 22, 2017, at 3:38 PM

I have used jquery-ui-1.7.2 datepicker in my code. I want to change the date in 'yy-mm-dd' format. But It doesn't change and takes default value.

Here is my code:

<div  id='myDate'>
 <input type="text" id="monthInput" class="form-control" name="water.month"  value="${water?.month}"  />
  </div>

and jquery:

  var now = new Date();
        var prevMonthFirstDate = new Date(now.getFullYear() - (now.getMonth() > 0 ? 0 : 1), (now.getMonth() - 1 + 12) % 12, 1);
        var prevMonthLastDate = new Date(now.getFullYear(), now.getMonth(), 0);
        $('#monthInput').datepicker({
            altFormat: 'yy-MM-dd',
            dateFormat: 'yy-MM-dd',
            startDate: prevMonthFirstDate,
            endDate: prevMonthLastDate
        });

What should I do?

Answer 1

Use dateFormat property instead of altFormat

    $('#monthInput').datepicker({
        dateFormat: 'yy-MM-dd'
    });
Answer 2

It was my fault. I have used bootstrap datepicker, not jquery datepicker. To change it, I have done this:

 var now = new Date();
        var prevMonthFirstDate = new Date(now.getFullYear() - (now.getMonth() > 0 ? 0 : 1), (now.getMonth() - 1 + 12) % 12, 1);
        var prevMonthLastDate = new Date(now.getFullYear(), now.getMonth(), 0);
        $('#monthInput').datepicker({
            format: 'yyyy-mm-dd',
            startDate: prevMonthFirstDate,
            endDate: prevMonthLastDate
        });
Rent Charter Buses Company
READ ALSO
Trying to match array values to input value but returns false in jQuery

Trying to match array values to input value but returns false in jQuery

I've been trying to match an array list of numbers to an input number value, but every time it goes the loop it doesn't seems to find a match at allSo the scenario is if input2 is matched to any of the values of input1 then it should show the alerts in the if statements

228
Scrollify.js navigation issue

Scrollify.js navigation issue

Am using scrollifyjs for page scroll

330
set index to table row

set index to table row

i have a table that has 30 rowsi wrote the below code to set number index to each row

260
jQuery variable redirect for html contact form

jQuery variable redirect for html contact form

Currently, I'm trying to set up a regular contact form with a variable redirect based on an option value through jQueryHere's the form:

294