How can I get a MySQL datetime stamp converted to a month using JavaScript?
MySQL date : 2021-12-14 10:15:56
output : December
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
2
Answers
This seems correct.
December is the 11th month, if you consider a zero based index.
According to the documentation, January is month 0, which would make December month 11:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMonth
You can use toLocaleString() method like this: