I think the main issue here is that you are trying to reuse snippets from Google without trying to understand what is doing what.
Magic numbers
This might be purely personal but I find 60*60*24
much easier to understand than 86400
.
Do not repeat yourself
What is the point of having fmt = '%Y-%m-%d %H:%M:%S'
if later on you rewrite strftime('%Y-%m-%d %H:%M:%S')
? You could write it : d1 = datetime.date.today().strftime(fmt)
making obvious to everyone that the same format is used.
Useless conversion between strings and dates
You are converting dates to string and string to date in a convoluted and probably not required way.
Usess conversion to int
You are using int(expr_date))
but expr_date
is defined as int(t) * 86400
which is an integer anyway. Also, I am not sure you would need the conversion of t
as an int.
Taking into account the different comments, my resulting not-tested code looks like :
def convUnixTime(t):
return (datetime.datetime.fromtimestamp(t*60*60*24)
- datetime.datetime.today()).days
Edit : I was using datetime.date.today()
instead of datetime.datetime.today()
. Also fixed the sign issue.
strftime
followed bystrptime
? \$\endgroup\$