Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split date in javascript

How to split the following date in javascript,

 var date='2002-01-01';
   The result should be as 20020101

Thanks..

like image 629
Hulk Avatar asked Jan 19 '26 01:01

Hulk


1 Answers

var date = "2002-01-01";

Either of the following will get you what you want:

  • date = date.replace(/-/g, "");
  • date = date.split("-").join("");
like image 126
Andy E Avatar answered Jan 21 '26 15:01

Andy E



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!