I have a modal which I use to edit some items. So I'm dynamically pre-filling the input fields using Javascript/JQuery. One of these items is a date.
The field on the form is showing '2016-07-01 00:00:00', which is the value coming from the database directly. This comes from
$(function() {
$('#edit-auction-modal').on("show.bs.modal", function (e) {
$('#edit-auction-modal ').find('input#auction-startdate').val($(e.relatedTarget).data('startdate'));
//$(e.relatedTarget).data('startdate') contains 2016-07-01 00:00:00
When I use "type=text"
<input type="text" class="form-control" id="startdate" placeholder="Start date" name="startdate" />
it displays the field as 2016-07-01 00:00:00 which is the field as it is stored in the database.
How can I change my Javascript code so that it displays 01-07-2016 in that field?
I tried changing the date format in the Javascript file via the following code:
var mydate = new Date($(e.relatedTarget).data('startdate'));
var dd = mydate.getDate()
var mm = mydate.getMonth()+1;
var yyyy = mydate.getFullYear();
if(dd<10){
dd='0'+dd
}
if(mm<10){
mm='0'+mm
}
var formattedStartDate = yyyy + '-' + mm + '-' + dd
var d = new Date(formattedStartDate);
$('#edit-auction-modal ').find('input#auction-startdate').val(d);
//printing to log the formattedStartDate gives 2016-07-01
However, in the input field however I'm getting Fri Jul 01 2016 00:00:00 GMT+0200 (CEST) now. How can I apply the format dd-mm-yyyy while still using a date?