Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert static / constant Date to specific format using Javascript

I have this basic javascript that outputs a constant / static date to the console:

var TodaysDate ="12/02/2021"; console.log(TodaysDate);

The output is simply: 12/02/2021

… Is there a way to get the date to output in the following format: YYYY-MM-DD, without changing the original variable text in the " " to 2021/12/02?
Thanks in advance for any assistance provided.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use simple ES6 methods to easily reverse your string

const TodaysDate ="12/02/2021"
const reverseDate = TodaysDate.split("/").reverse().join("/")

console.log(reverseDate)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading