When I set
datetime.now() to a variable (see example below), the value keeps updating each time the variable is accessed (instead of just setting the value as the time that the variable was initially declared). How do I capture the current time and store it as a variable value without it changing?
timestamp = datetime.now()
Can you post your code, please? Make sure to format it correctly.
I have updated the original post to include a code example.
Can you post your output as well? This is what I get when I run that code:
The outputs are all the same.
Okay, whoops, I confused myself at first:
It isn’t that printing that variable more than once in a row results in different values, it’s that it shows a different value each time I run the code (which would obviously produce a different result).
Sorry about that. My critical thinking had a wrench in it for a moment.
.now() is a method whose only job it is to retrieve the datetime properties from the system. The system clock is in milliseconds and like time itself, always going forward. Successive calls are always going to be different.