0

I'm getting the date string from sessionStorage and tying to convert into Date object of format MM/DD/YYYY so I can setDate to a datepicker.

HTML

<div id="demo"></div>
<label class="control-label" for="coverageStartDate">
   <input 
    type="text" id="coverageStartDate" 
    data-ng-model="coverageStartDate" 
    class="datepick input-small" 
    title="MM/dd/yyyy" 
    pattern="MM/DD/YYYY">
    <span class="datepick add-on" for="coverageStartDate">
      <i class="far fa-calendar-alt"></i>
    </span>
 </label>

JS

var startDate = "01/27/2020";
var coverageStartDate = new Date(startDate);
document.getElementById("demo").innerHTML = coverageStartDate;

$("#coverageStartDate").datepicker("setDate", coverageStartDate);

JSFiddle

dragonfly
  • 3,203
  • 7
  • 30
  • 52
  • Date objects don't have a format to them. You can convert them to a string *and then* format them, but the only information a date object has is the timestamp with a bunch of methods to manipulate it and to display it. – VLAZ Oct 24 '20 at 06:39
  • Does this answer your question? [jQuery UI DatePicker - Change Date Format](https://stackoverflow.com/questions/1328025/jquery-ui-datepicker-change-date-format) – VLAZ Oct 24 '20 at 06:42
  • @VALZ - I tried. But it didn't work for – dragonfly Oct 24 '20 at 06:51

0 Answers0