Reputation: 3
I am busy with a small project in python, I want help with troubleshooting if you want, If not, please assist with helping me figure out why every time the datetime gets logged, it only shows the time that the script was first run, and not the real local time?
See Code Below:
import datetime
Current_Time = datetime.datetime.now()
TimeFormat = Current_Time.strftime("%d %b %Y " + "at " + "%H:%M")
DayFormat = Current_Time.strftime("%d %b %Y ")
def Login_Report():
f= open("LoginReport.txt","w+")
f.write('Login Report For: ' + DayFormat + "\n\n")
#Create login report
Login_Report()
The above will give me the result of the login report only showing the time that I ran the script the first time.
Upvotes: 0
Views: 375
Reputation: 1115
You are not updating the time every time you are logging.
import datetime
def Login_Report():
Current_Time = datetime.datetime.now()
TimeFormat = Current_Time.strftime("%d %b %Y " + "at " + "%H:%M")
DayFormat = Current_Time.strftime("%d %b %Y ")
f= open("LoginReport.txt","w+")
f.write('Login Report For: ' + DayFormat + "\n\n")
#Create login report
Login_Report()
Upvotes: 1