How do I convert String into Date object

Chris Rebert clp2 at rebertia.com
Sat Aug 13 22:09:13 CEST 2011


On Sat, Aug 13, 2011 at 12:14 PM, MrPink <tdsimpson at gmail.com> wrote:
> Is this the correct way to convert a String into a Date?
> I only have dates and no time.
>
> import time, datetime
>
> oDate = time.strptime('07/27/2011', '%m/%d/%Y')
> print oDate

from datetime import datetime
the_date = datetime.strptime('07/27/2011', '%m/%d/%Y').date()

Cheers,
Chris



More information about the Python-list mailing list