Turns out, in my haste, I gave you incomplete (also known as bad) advice. For lack of a better way to describe it, Python is imputing the missing bits of time and using its best guess which, as it turns out, is a really bad guess. Consider this (the script takes Indigo out of the equation):
- Code: Select all
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import datetime as dt
var = "09-03 16:54"
now = dt.datetime.now()
time_var = dt.datetime.strptime(var, "%m-%d %H:%M")
diff = now - time_var
print(time_var)
print(diff)
1900-09-03 16:54:00
44017 days, 13:01:32.759175 (close to the result above which I failed to highlight).
Not very helpful.
Without knowing the complete value to work from, both datetime and very useful dateutil libraries struggle. You could "manually" adjust the input value with Python by adjusting the variable string before working with it, but that is fraught with peril. For example, if you assert the current year, this will break comparisons that span years.
I would suggest that the easiest and most robust way to solve the problem is to see if you can change the "shortened" variable values to full timestamps. If that's not possible, we can work on creating some custom scripts that will work for your circumstance.