Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44220
| References | <CABRP1o9nBwiPD9u8kqYyrKpoE-sRuqAb6L5xGWKt4WvUZigEBg@mail.gmail.com> |
|---|---|
| From | Kyle Shannon <kyle@pobox.com> |
| Date | 2013-04-23 15:41 -0600 |
| Subject | Re: datetime.strptime() not padding 0's |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.998.1366753313.3114.python-list@python.org> (permalink) |
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
Re: datetime.strptime() not padding 0's Kyle Shannon <kyle@pobox.com> - 2013-04-23 15:41 -0600
csiph-web