2015-12-26 python2> datetime> Implementation to take the difference in seconds from two ISO format datetime strings> Use .seconds ()

http://qiita.com/7of9/items/ceed758eaa49bc421c72 I want to take the difference as seconds in the continuation of.

Reference http://stackoverflow.com/questions/2788871/python-date-difference-in-minutes

Implementation http://ideone.com/H42MLS

from datetime import datetime as dt
from datetime import timedelta

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 - tdt2

diff_sec = (tdt1 - tdt2).seconds
print diff_sec

result


Success	time: 0.01 memory: 9176 signal:0
0:05:00
300

Recommended Posts

2015-12-26 python2> datetime> Implementation to take the difference in seconds from two ISO format datetime strings> Use .seconds ()
python> datetime> From date string (ISO format: 2015-12-09 12:40:08) to datetime type
How to get the date and time difference in seconds with python
How to use the C library in Python
Use PIL in Python to extract only the data you want from Exif
I wanted to use the Python library from MATLAB
How to use the model learned in Lobe in Python
I want to use the R dataset in python
Find the difference in Python
How to use the __call__ method in a Python class
Python / datetime> Implementation to convert YYYYMMDD format to YYYY / MM / DD
Allow Python to select strings in input files from folders
Determine the date and time format in Python and convert to Unixtime
[Python] Solving the import problem due to the difference in entry points
python: Use the variables defined in the string format as they are
How to use the asterisk (*) in Python. Maybe this is all? ..
[Introduction to Python] How to use the in operator in a for statement?
[Python] Explains how to use the format function with an example
Change the active version in Pyenv from anaconda to plain Python
In the python command python points to python3.8
How to use Mysql in python
Use the Flickr API from Python
How to use ChemSpider in Python
How to use PubChem in Python
Extract strings from files in Python
Tips for Python beginners to use the Scikit-image example for themselves 9 Use from C
Note: [Python3] Convert datetime to a string in any format you like
Connect to postgreSQL from Python and use stored procedures in a loop.
Use the LibreOffice app in Python (2) Manipulate calc (from macros and externals)
[Introduction to Python] How to use class in Python?
I want to use jar from python
Easy way to use Wikipedia in Python
How to use __slots__ in Python class
How to use regular expressions in Python
Convert from Markdown to HTML in Python
How to use is and == in Python
I want to use Python in the environment of pyenv + pipenv on Windows 10
Use libsixel to output Sixel in Python and output a Matplotlib graph to the terminal.
Use dHash to locate on the course from a scene in a racing game
3 ways to parse time strings in python [Note]
[Python] How to use two types of type ()
[Python] How to change the date format (display format)
Study from Python Hour7: How to use classes
How to use Python Image Library in python3 series
From file to graph drawing in Python. Elementary elementary
Minimal implementation to do Union Find in Python
Specify the Python executable to use with virtualenv
To dynamically replace the next method in python
[Bash] Use here-documents to get python power from bash
Summary of how to use MNIST in Python
About the difference between "==" and "is" in python
Draw graphs in Julia ... Leave the graphs to Python
Use cryptography module to handle OpenSSL in Python
Use Python in your environment from Win Automation
The easiest way to use OpenCV with python
The trick to write flatten concisely in python
[Algorithm x Python] How to use the list
Use the Python framework "cocotb" to test Verilog.
I want to use ceres solver from python
How to get the files in the [Python] folder
How to use tkinter with python in pyenv