Question and answer is powered by AnsPress.io
In my JS code, I have got the input date value to used this code.
<script> var mydate = $('#date').val(); console.log(mydate); </script>
Get Output: 16-10-2020
But I want to change the formate dd/mm/yyyy to mm/dd/yyyy. So that I will get the value 2020-20-16. How can I do that?
Apply this code:
<script> var mydate = $('#date').val(); var datearray = mydate.split("-"); var newdate = datearray[1] + '-' + datearray[0] + '-' + datearray[2]; console.log(newdate); </script>