Languages
[Edit]
EN

Python - convert string to datetime

0 points
Created by:
Mark-Rotteveel
537

In this article, we would like to show you how to convert a string into datetime in Python.

Quick solution:

Where:

  • %b - abbreviated month name,

  • %d - day of the month (01 to 31),

  • %Y - year including the century,

  • %I - hour (01 to 12),

  • %M - minute

  • %p - either am or pm according to the specified value.

Practical example

Edit

In this example, we convert a string into a datetime object with specified format using strptime() method.

Output:

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Python - string (popular problems)

Python - convert string to datetime
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join