How to Convert string ‘yyyy-mm-dd’ into DateTime in Python

In this lesson we want to learn How to Convert string ‘yyyy-mm-dd’ into DateTime in Python.

Python is high level, interpreted programming language. it was created in 1980s by Guido van Rossum and was first released in 1991. Python is known for its clear and simple syntax, and it makes it easy to read and write. it is dynamically typed, it means that you don’t need to declare the data type of variable before using it, and supports multiple programming paradigms, including object oriented, procedural and functional programming.

Python is widely used in different applications including web development, scientific computing, data analysis, artificial intelligence and more. it is also popular language for beginners due to its simplicity and readability, making it a great choice for educational purposes.




How to Convert string ‘yyyy-mm-dd’ into DateTime in Python ?

In Python, you can convert string in the format ‘yyyy-mm-dd‘ into datetime object using the datetime module. you can use the datetime.strptime method to parse the string into datetime object. this is an example:





In this example, the string ‘2023-02-02’ is first converted into datetime object using the datetime.strptime method. ‘%Y-%m-%d’ format string specifies format of the input string, with %Y representing the year with century as decimal number, %m representing month as decimal number, and %d representing day of the month as decimal number. the resulting datetime object can then be used for further processing and manipulation, just like any other datetime object.



Learn More on Python

Leave a Comment