Created
April 29, 2022 08:39
-
-
Save atulkumar2/325edb4de790e857f246abd5ad4211a3 to your computer and use it in GitHub Desktop.
Check some date and datetime functioning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime, timedelta | |
date1 = datetime.now() | |
date2 = date1 + timedelta(days=1) | |
print(date1) | |
print(date2) | |
print(date1 > date2) | |
print(date1.date()) | |
print(date2.date()) | |
print('date1.date() > date2.date():', date1.date() > date2.date()) | |
print('date1.date() < date2.date():', date1.date() < date2.date()) | |
print('date2 - date1:', date2 - date1) | |
print('date2.date() - date1.date():', date2.date() - date1.date()) | |
print('date2 - date1 type:', type(date2 - date1)) | |
print('date2.date() - date1.date() type:', type(date2.date() - date1.date())) | |
print('date2 - date1 days:', (date2 - date1).days) | |
print('date2.date() - date1.date() days:', (date2.date() - date1.date()).days) | |
print('date2 - date1 days type:', type((date2 - date1).days)) | |
print('date2.date() - date1.date() days type:', type((date2.date() - date1.date()).days)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2022-04-29 08:37:49.524254
2022-04-30 08:37:49.524254
False
2022-04-29
2022-04-30
date1.date() > date2.date(): False
date1.date() < date2.date(): True
date2 - date1: 1 day, 0:00:00
date2.date() - date1.date(): 1 day, 0:00:00
date2 - date1 type: <class 'datetime.timedelta'>
date2.date() - date1.date() type: <class 'datetime.timedelta'>
date2 - date1 days: 1
date2..date() - date1.date() days: 1
date2 - date1 days type: <class 'int'>
date2..date() - date1.date() days type: <class 'int'>