- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find if 24 hrs have passed between datetimes in Python?
To find out if 24 hrs have passed between datetimes in Python, you will need to do some date math in Python. So if you have 2 datetime objects, you'll have to subtract them and then take the timedelta object you get as a result and use if for comparision. You can't directly compare it to int, so you'll need to first extract the seconds from it.
from datetime import datetime NUMBER_OF_SECONDS = 86400 # seconds in 24 hours first = datetime(2017, 10, 10) second = datetime(2017, 10, 12) if (first - second).total_seconds() > NUMBER_OF_SECONDS: print("its been over a day!")
This will give the output −
its been over a day!
- How to find the files in Linux that have been changed in the last 24 hours?
- How to check if a date has passed in MySQL?
- 24-hour time in Python
- Python – Test if Rows have Similar frequency
- Plotting a cumulative graph of Python datetimes in Matplotlib
- How to find if a directory exists in Python?
- How to know if your child have allergy symptoms?
- How are parameters passed in C#?
- Python - Check if two lists have any element in common
- 24 Game in C++
- How are arguments passed by value or by reference in Python?
- Find whether all tuple have same length in Python
- How to find difference between 2 files in Python?
- C program to find amount of volume passed through a tunnel