Created
November 26, 2020 17:07
-
-
Save ahmedshahriar/b49f4ef8d741b90314f5fb96f6dc561d to your computer and use it in GitHub Desktop.
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
""" | |
code snippet to add/subtract datetime object | |
https://github.com/ahmedshahriar | |
""" | |
from datetime import datetime, timedelta | |
# addition | |
d = datetime.now() + timedelta(days=1, weeks=1, hours=19,seconds=1,milliseconds=1,microseconds=1) | |
#subtraction | |
d = datetime.now() - timedelta(days=1, weeks=1, hours=19,seconds=1,milliseconds=1,microseconds=1) | |
d.strftime('%Y-%m-%d %H:%M:%S') | |
# output sample | |
# 2020-12-05 12:05:36 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment