How do I convert String into Date object
tdsimpson at gmail.com
Sat Aug 13 22:25:07 CEST 2011
BTW, here is the Python version I'm using.
Will this make a difference with the solutions you guys provided?
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Also, what editor do you guys use?
There are so many to chose from.
On Aug 13, 4:11 pm, Rafael Durán Castañeda
<rafadurancastan... at gmail.com> wrote:
> You can use datetime objects:
> >>> dt1 = datetime.datetime.strptime('07/27/2011',"%m/%d/%Y")
> >>> dt2 =datetime.datetime.strptime('07/28/2011',"%m/%d/%Y")
> >>> dt1 == dt2
> >>> dt1 > dt2
> >>> dt1 < dt2
> >>> dt1 - dt2
> On 13/08/11 21:26, MrPink wrote:
> > I have file of records delimited by spaces.
> > I need to import the date string and convert them into date datatypes.
> > '07/27/2011' 'Event 1 Description'
> > '07/28/2011' 'Event 2 Description'
> > '07/29/2011' 'Event 3 Description'
> > I just discovered that my oDate is not an object, but a structure and
> > not a date datatype.
> > I'm stumped. Is there a way to convert a string into a date datatype
> > for comparisons, equality, etc?
> > Thanks,
> > On Aug 13, 3:14 pm, MrPink<tdsimp... 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
> >> Thanks,
More information about the Python-list