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


Groups > comp.lang.python > #56495

datetime.timedelta.replace?

Date 2013-10-09 10:15 -0500
Subject datetime.timedelta.replace?
From Skip Montanaro <skip@pobox.com>
Newsgroups comp.lang.python
Message-ID <mailman.897.1381331756.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web