Skip to content
Advertisement

How do I implement the datetime module into my code?

JavaScript

So how do I make the string a date?

The error:

JavaScript

Advertisement

Answer

When you’re creating your object you have to enclose the value inside quotes:

JavaScript

Just 21.12.1999 by itself isn’t a valid Python definition of anything.

You can then use strptime of the datetime.datetime module to parse it into a datetime, and retrieve the date from that value:

JavaScript

The %d corresponds to the day, the %m the month and %Y to the year in the string being sent in. Calling date() on the datetime drops the time-part and returns a pure date instead.

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