
datetime said midnight. Server logged 5 AM.
datetime said midnight. Server logged 5 AM. Built a scheduler that ran tasks at midnight. Worked fine on my laptop. Deployed to AWS and everything started running at 5 AM. What happened I was scheduling database backups using Python's datetime. Simple code: from datetime import datetime , time import schedule def backup_database (): print ( f " Backup started at { datetime . now () } " ) # database backup logic here schedule . every (). day . at ( " 00:00 " ). do ( backup_database ) while True : schedule . run_pending () time . sleep ( 60 ) Ran it locally (Peru timezone UTC-5), worked perfect. Midnight backups like clockwork. Deployed to AWS EC2 instance (UTC timezone). Checked logs next morning and backups ran at 5 AM local time. Why it broke The schedule library uses local server time. My EC2 instance defaulted to UTC. When I said "00:00", it scheduled for UTC midnight, which is 5 AM Peru time. I assumed datetime was timezone aware. It's not unless you explicitly make it. What fixed
Continue reading on Dev.to Python
Opens in a new tab



