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


Groups > comp.lang.python > #44220

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

Path csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.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.015
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'subject:not': 0.03; 'received:209.85.223': 0.03; '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; '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; '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=VfSQ6/v2e9J9pTmQ5IiKQoHGezI=; b=dAv4qX 9NSgnbY5lFq7HBx1/ONhfnMAeFJJrJbqS++jtlfu1Hbw4XG96NR58botq+WdQj7P Rzs60bmJOCW0rhpZVSBIoXkxN3jSDfF1yRI/4AeuvRax03Y57yHrpiOPc8bt2qz0 G2RFBWdkxcyTYsyjuQXZ80UeoCxU2i3CsYqWk=
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=d17uuFi88GZ9hRZjrdKPPs1YcRxceY88 Iu8qx0B9lr3gr5GYRqhbv8nthI34r/QKrlJzVP8o0HRvTU042u/ulB9XcyTet50m r2RGVj4RfKitfMv2ytP6AYr7YFPumRgesfsrjz9Z0cHSDhWpPiuB65BVQjCf5mqb fItseLDIESA=
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=zykMlf/76El4uqvNqryMqcdQfEDtXBFThbXUjJ3Wj5c=; b=oBOSIgVRd+BjNyB7SXNrKU94Ehd8juPa+KlIzHYvipN+k9W9ekou/p+XQHvuqcFRaR vSuN5JgZcirqBRbU8dJP/ZENGPpAj4xqX8HqP4nCTNE+gdvGPMBInrOlzSO4rrrbsyp3 eqJt61oIuIaFd/khKzJVgcYr++t/WKlWP7/2XhovXN6fXTdQ3C0fnD339Cp6U8VzCvvo 3yj3e+8+IIXYFUHP7r5udsGOq74/bJ+I2xWjG04d1iRNv+IrhlTtRDp9PzrKFP4NA5xo Vu7C8wb7fI1AtaQ7/b0saXpZA2o+QrHEnMM4FqUME4DPGQjZJnf0vge6JV0XLOUwvsOu 2f5g==
X-Received by 10.50.1.38 with SMTP id 6mr25793769igj.106.1366753309108; Tue, 23 Apr 2013 14:41:49 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <CABRP1o9nBwiPD9u8kqYyrKpoE-sRuqAb6L5xGWKt4WvUZigEBg@mail.gmail.com>
References <CABRP1o9nBwiPD9u8kqYyrKpoE-sRuqAb6L5xGWKt4WvUZigEBg@mail.gmail.com>
From Kyle Shannon <kyle@pobox.com>
Date Tue, 23 Apr 2013 15:41:34 -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 9ABD0A72-AC5E-11E2-8F09-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.998.1366753313.3114.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1366753313 news.xs4all.nl 2251 [2001:888:2000:d::a6]:58555
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:44220

Show key headers only | View raw


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'

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:41 -0600

csiph-web