Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5559
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'implements': 0.05; 'operations.': 0.05; 'delta': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'def': 0.13; "'int'": 0.16; '(1,': 0.16; '30)': 0.16; '3600,': 0.16; '60,': 0.16; 'from:addr:yahoo.com.ar': 0.16; 'traceback': 0.16; '(most': 0.16; 'tue,': 0.20; 'last):': 0.23; "i'm": 0.26; 'problem': 0.29; 'class': 0.29; 'charset:iso-8859-15': 0.31; 'operand': 0.31; 'typeerror:': 0.31; 'import': 0.32; 'to:addr:python-list': 0.32; 'using': 0.34; 'header:X-Complaints-To:1': 0.34; 'file': 0.35; 'header:User-Agent:1': 0.35; '"",': 0.35; 'mathematical': 0.38; 'received:org': 0.38; 'to:addr:python.org': 0.39; 'header:Mime- Version:1': 0.39; 'how': 0.39; 'add': 0.39; 'header:Received:5': 0.40; '2011': 0.62; '30,': 0.80; '-0300,': 0.84; 'datetime': 0.84; 'genellina': 0.84; 'hours)': 0.84; 'gabriel': 0.91; 'received:186': 0.91; 'type(s)': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | "Gabriel Genellina" <gagsl-py2@yahoo.com.ar> |
| Subject | Re: Datetime.timedelta |
| Date | Tue, 17 May 2011 08:44:48 -0300 |
| References | <BANLkTimhrWrXrtLWtdzO3nJdX206U05biA@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=iso-8859-15; format=flowed; delsp=yes |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | 186.19.171.200 |
| User-Agent | Opera Mail/11.10 (Win32) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1667.1305632687.9059.python-list@python.org> (permalink) |
| Lines | 41 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1305632687 news.xs4all.nl 49175 [::ffff:82.94.164.166]:38849 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:5559 |
Show key headers only | View raw
En Tue, 17 May 2011 07:44:08 -0300, Tsolmon Narantsogt <mnts26@gmail.com> escribió: > I'm using datetime.timedelta and i have a problem > > delta = 1 day, 2:30:00 > hours = delta.days * 8 > > how to add 8 + 2:30:00 Just operate with it as it were a number. The timedelta class implements all "sane" mathematical operations. py> from datetime import * py> def timedelta_from_dhms(days=0, hours=0, mins=0, secs=0): ... return timedelta(days, hours*3600 + mins*60 + secs) ... py> delta = timedelta_from_dhms(1, 2, 30) py> delta datetime.timedelta(1, 9000) py> hours = delta.days * 8 py> delta + hours Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'datetime.timedelta' and 'int' py> hours = timedelta_from_dhms(0, delta.days * 8) py> hours datetime.timedelta(0, 28800) py> delta + hours datetime.timedelta(1, 37800) py> def dhms_from_timedelta(td): ... return td.days, td.seconds // 3600, (td.seconds % 3600) // 60, td.seconds % 60 ... py> dhms_from_timedelta(delta + hours) (1, 10, 30, 0) -- Gabriel Genellina
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Datetime.timedelta "Gabriel Genellina" <gagsl-py2@yahoo.com.ar> - 2011-05-17 08:44 -0300
csiph-web