How can I remove the leading two digits from the year in the format 08/07/2018
in JavaScript? I just want to display 08/07/18.
Asked
Active
Viewed 1,444 times
-5

Kahn
- 429
- 3
- 6
- 19
-
2Same way you would with a string (convert to string first, then convert back to number). See https://stackoverflow.com/a/5131876/5079258 – Alan Friedman Jul 12 '18 at 12:37
3 Answers
3
You can use String.slice
.
var dateStr = '19/02/2008';
var output = dateStr.slice(0, 6) + dateStr.slice(8);
console.log(output);

Bharata
- 13,509
- 6
- 36
- 50
-
3And why is that essential information not mentioned in your question? – David Thomas Jul 12 '18 at 12:42
-
-
-
1
-
1
If its a string you could do "1990".substr(2) else you get the year from date object and do the same thing.
Also please always share your solution always. It would be really appreciated if you share what you have done.

Ankit
- 51
- 3
1
Here is the code to remove the first two digits:
var myString = "1990";
var newString = myString.substr(2);
//output:
//myString = 90