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


Groups > comp.lang.python > #44222

Re: datetime.strptime() not padding 0's

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <kyle@pobox.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'subject:not': 0.03; 'received:209.85.223': 0.03; 'shannon': 0.07; 'string': 0.09; 'cc:addr:python-list': 0.11; "'%b": 0.16; '23,': 0.16; 'from:addr:pobox.com': 0.16; 'isnt': 0.16; 'padded': 0.16; 'received:208.72.237.35': 0.16; 'received:smtp.pobox.com': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'received:pobox.com': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'wondering': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; '>>>>': 0.31; 'received:208.72': 0.31; 'received:208.72.237': 0.31; 'run': 0.32; 'url:python': 0.33; 'skip:d 20': 0.34; 'received:209.85': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'subject:skip:d 10': 0.36; 'url:listinfo': 0.36; 'doing': 0.36; 'url:org': 0.36; 'wrong': 0.37; 'received:209': 0.37; 'pm,': 0.38; 'url:mail': 0.40; 'how': 0.40; 'read': 0.60; 'received:208': 0.61; 'to:addr:gmail.com': 0.65; 'confusing': 0.84; 'kyle': 0.84; 'pad': 0.84; 'type(s)': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=mime-version :in-reply-to:references:from:date:message-id:subject:to:cc :content-type; s=sasl; bh=vMMaWmpLivWn2Faoiabp+l8lluk=; b=hPjJlD GhSAFqdPiJmCI+ejTAXtxzyKVmrrIQeD+IpE7iAOW44QYeeL+9oPLII8+udHE4+L ax74e+WFtEZHl5+T+clIDzkDNQqGi8tcIkIMaApvsXemgg8cVg1nB1zkHJKDg7BO jCSDNQ/8jjxMKjgmNbex3d7OjHcYGClrvWrt0=
DomainKey-Signature a=rsa-sha1; c=nofws; d=pobox.com; h=mime-version :in-reply-to:references:from:date:message-id:subject:to:cc :content-type; q=dns; s=sasl; b=qCsD7UPf6WTFf6olfTey6ZnjfspmQ/EY zgrI78bnzkQwuplcwDVAd/SSpjTxON0EZ9Hwx3D+4bi3emkv5c9QlE6VLpsGoUqk OiX8MXzLCbG6pehF06yJBQ3zsrzmqcwUfdwE2isVLv6MlWCHIHmuqyXTHftmoi8J sJI9MYd0L6M=
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=cvlrxzkazXB+czT9OSCLI9mDdWGsW9HeRxiNSRrSmOk=; b=TBoVwWkkXAr1FYX6qIb4eY00eAMGZjpTMDf1K77s+/rcH9U+0mr2aH6RfRqoSbzFFu uvoBWJUIXQ/Buc7UxQxXm+03JFY5GTtq/1Z+Jf0mW635iji1npB/y3MdfM6kabsMEQfu 37Yx8RsqE1erlmwvMRqQqOThtFdAftL1ufkFYsc9B7LuvpeKBO80I6EcNxOxPkgK3luE A0xnpq15vb8hYQIYLe1wyeP0uUtff1u6TryhxbRhDUbtWJyTiLuuTv9BN6GDIAgIiX2y 1fzvnWv1YpXmtSh+SWkKvtwos0AC2v9zsQSnfBfZ19R4TicWDB2DVLdvBzTS1vgNR+WY j+5g==
X-Received by 10.50.87.69 with SMTP id v5mr10321714igz.54.1366753463407; Tue, 23 Apr 2013 14:44:23 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <CAJ0mEz069p8G2Xfw58okXTf-Ch=QwEtasreJn2s0XHaTv84bvA@mail.gmail.com>
References <CABRP1o9nBwiPD9u8kqYyrKpoE-sRuqAb6L5xGWKt4WvUZigEBg@mail.gmail.com> <CAJ0mEz069p8G2Xfw58okXTf-Ch=QwEtasreJn2s0XHaTv84bvA@mail.gmail.com>
From Kyle Shannon <kyle@pobox.com>
Date Tue, 23 Apr 2013 15:44:08 -0600
Subject Re: datetime.strptime() not padding 0's
To Rodrick Brown <rodrick.brown@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
X-Pobox-Relay-ID F6AF899A-AC5E-11E2-A5A9-BCFF4146488D-51336117!b-pb-sasl-quonix.pobox.com
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.999.1366753466.3114.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1366753466 news.xs4all.nl 2256 [2001:888:2000:d::a6]:33180
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:44222

Show key headers only | View raw


On Tue, Apr 23, 2013 at 3:41 PM, Kyle Shannon <kyle@pobox.com> wrote:
> On Tue, Apr 23, 2013 at 3:14 PM, Rodrick Brown <rodrick.brown@gmail.com> wrote:
>> I thought I read some where that strptime() will pad 0's for day's for some
>> reason this isnt working for me and I'm wondering if i'm doing something
>> wrong.
>>
>>>>> from datetime import datetime
>>>>> dt = datetime.strptime('Apr 9 2013', '%b %d %Y')
>>>>> dt.day
>> 9
>>>>>
>>
>> How can I get strptime to run 09? instead of 9
>>
>>
>> --RB
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
> dt.day is an integer:
>
>>>> from datetime import datetime
>>>> dt = datetime.strptime('Apr 9 2013', '%b %d %Y')
>>>> type(dt.day)
> <type 'int'>
>
> I think you are confusing strftime() with strptime():
>
>>>> dt.strftime('%b %D %Y')
> 'Apr 04/09/13 2013'
>
> or if you just want a 0 padded string for the day, use string formatting:
>
>>>> s = '%02d' % dt.day
>>>> type(s)
> <type 'str'>
>>>> s
> '09'


Whoops, wrong cut/paste, I meant:

>>> dt.strftime('%b %d %Y')
'Apr 09 2013'

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


Thread

Re: datetime.strptime() not padding 0's Kyle Shannon <kyle@pobox.com> - 2013-04-23 15:44 -0600

csiph-web