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

converting a mysql Datetime stamp to a month using javascript

How can I get  a MySQL datetime stamp converted to a month using JavaScript?

MySQL date : 2021-12-14 10:15:56

output : December

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

using JavaScript code

I tried this

const moonLanding = new Date(‘2021-12-14 10:15:56’);
// const moonLanding = new Date(‘July 20, 69 00:20:18’);

console.log(moonLanding.getMonth());
output is > 11

>Solution :

You can use toLocaleString() method like this:

const timestamp = '2021-12-14 10:15:56';
const date = new Date(timestamp);

const monthName = date.toLocaleString('en-US', { month: 'long' });

console.log(monthName); 
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