Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #56495 > unrolled thread

datetime.timedelta.replace?

Started bySkip Montanaro <skip@pobox.com>
First post2013-10-09 10:15 -0500
Last post2013-10-09 10:15 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  datetime.timedelta.replace? Skip Montanaro <skip@pobox.com> - 2013-10-09 10:15 -0500

#56495 — datetime.timedelta.replace?

FromSkip Montanaro <skip@pobox.com>
Date2013-10-09 10:15 -0500
Subjectdatetime.timedelta.replace?
Message-ID<mailman.897.1381331756.18130.python-list@python.org>
Datetime objects have a replace method, but timedelta objects don't.
If I take the diff of two datetimes and want to zero out the
microseconds field, is there some way to do it more cleanly than this?

delta = dt1 - dt2
zero_delta = datetime.timedelta(days=delta.days, seconds=delta.seconds)

I guess that's not bad, but replace() seems cleaner (or at least more
congruent with datetime objects).

Skip

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web