I am trying to create a function on javascript to bring the date from my database in format (yyyy-mm-dd) and display it on the page as (dd/mm/yy).
I would appreciate any help.
Thanks.
PD: Let me know if you need more clarification.
If you're sure that the date that comes from the server is valid, a simple RegExp can help you to change the format:
function formatDate (input) {
var datePart = input.match(/\d+/g),
year = datePart[0].substring(2), // get only two digits
month = datePart[1], day = datePart[2];
return day+'/'+month+'/'+year;
}
formatDate ('2010/01/18'); // "18/01/10"
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