Skip to content

Instantly share code, notes, and snippets.

@pca2
Forked from kathawala/datetime_to_cron.py
Last active March 23, 2022 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pca2/8baeda4d4485689b4077095ffce430a3 to your computer and use it in GitHub Desktop.
Save pca2/8baeda4d4485689b4077095ffce430a3 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)
from datetime import datetime
def datetime_to_cron(dt):
return f"{dt.minute} {dt.hour} {dt.day} {dt.month} *"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment