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