python> datetime> From date string (ISO format: 2015-12-09 12:40:08) to datetime type

I want to convert from a format like 2015-12-09 12:40:08 (it seems to be ISO format) to datetime.

Reference http://qiita.com/shibainurou/items/0b0f8b0233c45fc163cd

I implemented it as follows.

http://ideone.com/IaAbuS

from datetime import datetime as dt

strdt1 = "2015-12-09 12:40:08"
strdt2 = "2015-12-09 12:35:08"
tdt1 = dt.strptime(strdt1, "%Y-%m-%d %H:%M:%S")
tdt2 = dt.strptime(strdt2, "%Y-%m-%d %H:%M:%S")

print tdt1
print tdt2

print tdt1 - tdt2

result


Success	time: 0.02 memory: 9184 signal:0
2015-12-09 12:40:08
2015-12-09 12:35:08
0:05:00

Recommended Posts

python> datetime> From date string (ISO format: 2015-12-09 12:40:08) to datetime type
[python] Convert date to string
Conversion of string <-> date (date, datetime) in Python
Python string format
2015-12-26 python2> datetime> Implementation to take the difference in seconds from two ISO format datetime strings> Use .seconds ()
Timezone specification when converting a string to datetime type in python
Receive date type (datetime) with ArgumentParser [python]
Python2 string type
Python string format
Note: [Python3] Convert datetime to a string in any format you like
[Python] How to change character string (str) data to date (strptime of datetime)
Convert "number" of excel date to python datetime
[Python] How to change the date format (display format)
Create a datetime object from a string in Python (Python 3.3)
How to handle datetime type in python sqlite3
String to Unicode Escape Sequence Format for Python
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
[Python2] Date string-> UnixTime-> Date string
[Python] I tried to get the type name as a string from the type function
Convert date timezone (time difference) in Python (from string)
0 Convert unfilled date to datetime type with regular expression
Python --Notes when converting from str type to int type
Post from Python to Slack
Python indentation and string format
Cheating from PHP to Python
Switch from python2.7 to python3.6 (centos7)
Connect to sqlite from python
[Python 2/3] Parse the format string
String date manipulation in Python
String format with Python% operator
Python / datetime> Implementation to convert YYYYMMDD format to YYYY / MM / DD
How to set the extended iso8601 format date to the Dataframe index
Determine the date and time format in Python and convert to Unixtime
Practice! !! Introduction to Python (Type Hints)
Create folders from '01' to '12' with python
[Lambda] [Python] Post to Twitter from Lambda!
Try to extract a character string from an image with Python3
How to get a string from a command line argument in python
python datetime format quick reference table
Connect to utf8mb4 database from python
Python (from first time to execution)
Post images from Python to Tumblr
6 ways to string objects in Python
Python vba to create a date string for creating a file name
How to calculate date with python
How to access wikipedia from python
Python to switch from another language
Misunderstanding due to datetime type subtraction
Did not change from Python 2 to 3
Update Python on Mac from 2 to 3
C language to see and remember Part 2 Call C language from Python (argument) string
[Introduction to Python] How to write a character string with the format function
[Python] Fluid simulation: From linear to non-linear
[Introduction to Udemy Python3 + Application] 28. Collective type
From Python to using MeCab (and CaboCha)
Reintroduction to Python Decorators ~ Learn Decorators by Type ~
Use PostgreSQL data type (jsonb) from Python
How to update Google Sheets from Python
Send a message from Python to Slack
[Introduction to Udemy Python3 + Application] 21. Tuple type