Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery-datepicker issues formatting date
    primarykey
    data
    text
    <p>I have 2 datepickers in jquery where I add a single day to the date of one picker and assign it to another date picker like so:</p> <pre><code> /*assign date pickers*/ $("#MainContent_txtActualShipDate").datepicker({ dateFormat: 'mm/dd-yyyy', changeMonth: true, changeYear: true, showOtherMonths: true, selectOtherMonths: true }); $("#MainContent_txtExpectedShipDate").datepicker({ changeMonth: true, changeYear: true, showOtherMonths: true, selectOtherMonths: true, onSelect: function (selectedDate) { var date = $(this).datepicker('getDate'); if (date) { date.setDate(date.getDate() + 1); $("#MainContent_txtActualShipDate").val(date); } } }); </code></pre> <p>Notice the <code>onSelect</code> function adds a single date and assigns it to <code>#MainContent_txtActualShipDate</code> but the value it gets is "TUE APR 24 2012 00:00:00". I want it to be simply '04/24/2012' so mm/dd/yyyy. I read the jquery ui docs and looked up some examples on stackoverflow but none of them worked. Is there anyone that can look at this code and edit to get the format I want?</p> <h1>Edit</h1> <p>Here is what I change it to:</p> <pre><code> $("#MainContent_txtExpectedShipDate").datepicker({ dateFormat: 'mm/dd-yyyy', changeMonth: true, changeYear: true, showOtherMonths: true, selectOtherMonths: true, onSelect: function (selectedDate) { var date = $(this).datepicker('getDate'); if (date) { date.setDate(date.getDate() + 1); var formattedDate = $.datepicker.formatDate('mm/dd-yyyy', date); $("#MainContent_txtActualShipDate").val(formattedDate); // $("#MainContent_txtActualShipDate").val(date); } } }); </code></pre> <p>But it shows the year twice 04/12/20122012.</p> <h1>Answer</h1> <p>Here is what worked for others in the future:</p> <pre><code>/*assign date pickers*/ $("#MainContent_txtActualShipDate").datepicker({ dateFormat: 'mm/dd/yy', changeMonth: true, changeYear: true, showOtherMonths: true, selectOtherMonths: true }); $("#MainContent_txtExpectedShipDate").datepicker({ dateFormat: 'mm/dd/yy', changeMonth: true, changeYear: true, showOtherMonths: true, selectOtherMonths: true, onSelect: function (selectedDate) { var date = $(this).datepicker('getDate'); if (date) { date.setDate(date.getDate() + 1); var formattedDate = $.datepicker.formatDate('mm/dd/yy', date); $("#MainContent_txtActualShipDate").val(formattedDate); } } }); /*end assign date pickers*/ </code></pre> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload