I am getting the date from MySQL
as 2021-10-30
(YYYY-MM-DD) and storing this date in a variable in JavaScript.
But I want to change 2021-10-30
to 2021-Oct-30
, then how can I do this in javascript ? I don't want to do this in MySQL.
Asked
Active
Viewed 33 times
0

diana
- 39
- 6
-
1What's stopping you? Create an array of month names and index it using the middle part of the date. – Barmar Nov 03 '21 at 05:09
-
You could also use the `moment.js` library. – Barmar Nov 03 '21 at 05:10
-
Any other direct solution without creating an array. Like we can do this without an array in PHP – diana Nov 03 '21 at 05:16
-
JavaScript doesn't have built-in date formatting functions like PHP does. – Barmar Nov 03 '21 at 05:20
-
Read the linked question, it has over 50 ways to do it. – Barmar Nov 03 '21 at 05:21
-
Dates in YYYY-MM-DD format are parsed as UTC, so you can use the built–in parser and *toLocale* string with appropriate options: `new Date('2021-10-30').toLocaleString('en-ca',{year:'numeric', month:'short', day:'2-digit', timeZone:'UTC'}).match(/\w+/g).join('-')` gives "2021-Oct-30". – RobG Nov 03 '21 at 06:10
-
So now I am currently using `toLocaleString` – diana Nov 03 '21 at 10:17