Michael Michael - 5 months ago 11
AngularJS Question

How to remove sub string from string?

I have this string:

27/06/2016


or:

15/10/2005


I need to convert the string above to this:

27/06/16


or

15/10/05


How can I implement it in Javascript?

Answer

You can you simple string manipulation methods:

function shortDate(str) 
{
    return str.substring(0, 6) + str.substring(8, 10);
}

var dt = shortDate('27/06/2016');
// returns 27/06/16