0

Good Day Everyone,

I would like to seek your help in displaying the current date to input type"date" when button is click.
format is like this or mm/dd/yyyy. thank you

$(function() {
  $('#btncheckout').click(function() {
    var time = new Date();
    $('subdateout').val(time.toDateString());
  });
});
<div class="input-group-sm mb-3 row align-middle ">
  <input type="date" name="subdateout" id="subdateout" class="form-control rounded-0 w3-tiny" max="<?php echo date('Y-m-d');?>" value="">
</div>

<div class="col-sm-3">
  <button type="button" id="btncheckout" class="btn btn-primary btn-sm rounded-0">Check Out</button>
</div>

</div>
M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
king kong
  • 1
  • 2

1 Answers1

0

Here's a down and dirty way to get it into the format you want.

var time = new Date();
var datestring = ("0"+(time.getMonth()+1)).slice(-2) + "/" + ( "0" + time.getDate()).slice(-2) + "/" + 
    time.getFullYear() 

console.log(datestring)

Taken from this amazing collection of date format options. How to format a JavaScript date

Kinglish
  • 23,358
  • 3
  • 22
  • 43