Skip to content
Advertisement

Convert Date in JavaScript (from a Python Dataset)

How do I edit the date format that gets returned from a dataset from Python via a Flask App in Javascript?

It currently shows up as datetime, but I want it to show up as a custom date format.

The best type of answer would help me to understand how to access those date values and create a custom date, such as ‘Monday, 6 June 2022’. But if you can just turn it into a date, without the time, that may also suffice.

enter image description here

Python

JavaScript

HTML/JavaScript

JavaScript

If you’re wondering about why the values are nested like this, there’s some custom CSS styling (not included here) to make them look better.

Libraries

JavaScript

Advertisement

Answer

I recommend using the MomentJS library to change the format of the date.
Just include the library in the header.

JavaScript

Then you can change the date by choosing the format.

JavaScript

As a little tip, I advise you to choose your variable names in such a way that they do not collide with predefined names in the language. In JavaScript, the CamelCase notation is used as the standard.

JavaScript

A variant with Date.prototype.toLocaleDateString() is this.

JavaScript

The output should look like this.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement