Created
April 21, 2020 22:23
-
-
Save kathawala/278676b4b80eb4d1f344dbcd84192375 to your computer and use it in GitHub Desktop.
Converts a python datetime to a crontab expression which fires once (at the date+time specified in the python datetime object)
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 | |
def datetime_to_cron(dt): | |
# FYI: not all cron implementations accept the final parameter (year) | |
return f"cron({dt.minute} {dt.hour} {dt.day} {dt.month} ? {dt.year})" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Had a problem with datetime.strftime running on Windows. It ran well on Linux, but in Windows it crashed with "Invalid String Format" error.
This fixed it, thank you very much!!