I am trying to convert a date from DD-MM-YYYY to MM-DD-YYYY. But it doesn't work for me. I tried this
var test = Date.parse('15-06-2010');
var SearchDate = moment('15-06-2010').format("MM-DD-YYYY");
var day = moment(new Date("15-06-2010"), "MM-DD-YYYY");
console.log(test);
console.log(day);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.5.1/moment.min.js"></script>
Help me.
SearchDate = moment(new Date(), “DD/MM/YYYY”);
To format a date as dd/mm/yyyy:Use the getDate() , getMonth() and getFullYear() methods to get the day, month and year of the date. Add a leading zero to the day and month digits if the value is less than 10 .
Moment JS allows displaying of date as per localization and in human readable format. You can use MomentJS inside a browser using the script method. It is also available with Node. js and can be installed using npm.
Try this:
var date = moment('15-06-2010', 'DD-MM-YYYY')
console.log(date.format('MM-DD-YYYY'))
You have to specify the input format for the date when parsing a date with momentjs.
Here 26-11-2019 will be converted to 11-26-2019
const date = moment('26-11-2019','DD-MM-YYYY').format('MM-DD-YYYY');
To the format method we can give any format, how you want the output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With