Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
How to split the following date in javascript,
var date='2002-01-01'; The result should be as 20020101
Thanks..
var date = "2002-01-01";
Either of the following will get you what you want:
date = date.replace(/-/g, "");
date = date.split("-").join("");
Add a comment
If it is just a string, you can do:
var date = ("2002-01-02").replace(/-/g, "");
Otherwise:
var now = new Date(); var date = now.getFullYear() + "" + (now.getMonth() + 1) + "" + now.getDate();
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.