0

I have a Windows Scheduled task that is scheduled to run a python script (.bat file) at 05:30 AM, 01:30PM and 10:30PM daily. The issue is that task scheduler will execute the script at the proper time but when the script pulls time using now = datetime.now() the hour is 1 hour off. Looking at the datetime settings on the computer appears to be normal and in sync.

Ex: Scheduled task runs at 05:30 but print(now) will show 06:30. There is a setting on scheduled task triggers that is 'synchronize across time' but that doesn't make a difference in the result. The weird thing is if you manually run the task from windows task scheduler then it will pull the correct times.

I made a simple script for testing purposes in an attempt to troubleshoot but I am stumped.

import os, time 
from datetime import date, datetime
def main():
  now = datetime.now()
  shift = now.strftime('%H')
  file = open("timecheck.txt","a")
  file.write(f'Time is: {now}\n Shift hour is: {shift}\n\n')
  file.close()
main()

The attached screenshot shows the mixmatched results. 12:30 scheduled task results to hour 13:30 but the manual run at 12:37 shows the proper time. Image showing the time discrepancy

  • Does this answer your question? [java Calendar, Date, and Time management for a multi-timezone application](https://stackoverflow.com/questions/19166995/java-calendar-date-and-time-management-for-a-multi-timezone-application) *For example, a task that runs every 24 hours would be scheduled by UTC time and not by the local time.* Or it could be a _daylight saving time_ one-hour difference? – JosefZ Aug 17 '22 at 16:21
  • I don't think this is a daylight savings time difference, when turning "adjust for daylight savings time" setting off on the computer then the time goes back an hour which doesn't match up with the issue of datetime.now() being 1 hour ahead. If this were a DST time issue then datetime.now() would be 1 hour behind. (unless I am wrong, been wrong plenty of times!) – nate8458 Aug 17 '22 at 18:37

0 Answers0