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


Groups > comp.lang.python > #11353

Re: How do I convert String into Date object

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rafadurancastaneda@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.051
X-Spam-Evidence '*H*': 0.90; '*S*': 0.00; 'subject:object': 0.07; 'comparisons,': 0.16; 'delimited': 0.16; 'etc?': 0.16; 'objects:': 0.16; 'wrote:': 0.16; 'received:74.125.82.44': 0.17; 'received :mail-ww0-f44.google.com': 0.17; 'thanks,': 0.18; '>>>': 0.18; 'convert': 0.19; 'header:In-Reply-To:1': 0.22; 'structure': 0.23; 'received:192.168.1.100': 0.23; 'pm,': 0.24; 'aug': 0.24; 'object,': 0.24; 'string': 0.26; "i'm": 0.27; 'correct': 0.28; 'import': 0.28; 'print': 0.29; 'there': 0.33; 'to:addr:python- list': 0.33; 'header:User-Agent:1': 0.34; 'message-id:@gmail.com': 0.34; 'from:charset:iso-8859-1': 0.35; 'subject:How': 0.35; 'file': 0.36; 'but': 0.37; 'received:74.125.82': 0.38; 'received:google.com': 0.38; 'subject:: ': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.39; 'received:74.125': 0.39; 'skip:d 20': 0.39; 'skip:= 50': 0.63; 'discovered': 0.68; 'records': 0.72; 'date?': 0.84; 'datetime': 0.84; 'spaces.': 0.84; 'skip:d 50': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=Gek0qQwGbodQGAcJS6d8cf6LT1mxA8ixLTCeDvOp8NM=; b=xPRtfrX661kqSifT1563n/CrYsc0MMHIHNnWaUJ2KC9wMwFzyKqYWz6VFjog5PMEr8 q3WDDjjZ4R1d6eXXg+uSHFEmW0f6wnz3Hk8NSNqIjJubrXsfiaku3wlS/Nd1POxrRPKd HtiCxNU6i8yEBa3sXkomUcrc7nkApCGuBoZ+M=
Date Sat, 13 Aug 2011 22:11:00 +0200
From Rafael Durán Castañeda <rafadurancastaneda@gmail.com>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Thunderbird/3.1.11
MIME-Version 1.0
To python-list@python.org
Subject Re: How do I convert String into Date object
References <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com>
In-Reply-To <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
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.2255.1313266271.1164.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1313266271 news.xs4all.nl 23894 [2001:888:2000:d::a6]:52141
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:11353

Show key headers only | View raw


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
False
 >>> dt1 > dt2
False
 >>> dt1 < dt2
True
 >>> dt1 - dt2
datetime.timedelta(-1)


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...@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,

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


Thread

How do I convert String into Date object MrPink <tdsimpson@gmail.com> - 2011-08-13 12:14 -0700
  Re: How do I convert String into Date object MrPink <tdsimpson@gmail.com> - 2011-08-13 12:26 -0700
    Re: How do I convert String into Date object Rafael Durán Castañeda <rafadurancastaneda@gmail.com> - 2011-08-13 22:11 +0200
      Re: How do I convert String into Date object MrPink <tdsimpson@gmail.com> - 2011-08-13 13:25 -0700
    Re: How do I convert String into Date object Peter Otten <__peter__@web.de> - 2011-08-13 22:29 +0200
    Re: How do I convert String into Date object Sibylle Koczian <nulla.epistola@web.de> - 2011-08-13 22:05 +0200
  Re: How do I convert String into Date object Chris Rebert <clp2@rebertia.com> - 2011-08-13 13:09 -0700
  Re: How do I convert String into Date object Roy Smith <roy@panix.com> - 2011-08-13 20:49 -0400
  Re: How do I convert String into Date object MrPink <tdsimpson@gmail.com> - 2011-08-13 22:44 -0700

csiph-web