Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python's timedelta: can't I just get in whatever time unit I want the value of the entire difference?

I am trying to have some clever dates since a post has been made on my site ("seconds since, hours since, weeks since, etc..") and I'm using datetime.timedelta difference between utcnow and utc dated stored in the database for a post.

Looks like, according to the docs, I have to use the days attribute AND the seconds attribute, to get the fancy date strings I want.

Can't I just get in whatever time unit I want the value of the entire difference? Am I missing something?

It would be perfect if I could just get the entire difference in seconds.

like image 209
Bjorn Avatar asked Feb 01 '09 03:02

Bjorn


1 Answers

It seems that Python 2.7 has introduced a total_seconds() method, which is what you were looking for, I believe!

like image 98
Ham Avatar answered Oct 05 '22 15:10

Ham