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


Groups > comp.lang.python > #11373

Re: How do I convert String into Date object

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.011
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'subject:object': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'comparisons,': 0.16; 'delimited': 0.16; 'etc?': 0.16; 'instance:': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; '>>>': 0.18; 'convert': 0.19; 'header:In-Reply-To:1': 0.22; 'structure': 0.23; 'object,': 0.24; 'string': 0.26; "i'm": 0.27; 'import': 0.28; '27,': 0.29; 'from:addr:web.de': 0.30; 'there': 0.33; 'to:addr:python-list': 0.33; 'header:User-Agent:1': 0.34; 'header:X-Complaints-To:1': 0.35; 'subject:How': 0.35; 'file': 0.36; 'but': 0.37; 'received:org': 0.38; 'subject:: ': 0.39; 'skip:d 40': 0.39; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'skip:d 20': 0.39; 'discovered': 0.68; 'received:62': 0.70; 'records': 0.72; 'datetime': 0.84; 'schrieb': 0.84; 'spaces.': 0.84; 'step,': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Sibylle Koczian <nulla.epistola@web.de>
Subject Re: How do I convert String into Date object
Date Sat, 13 Aug 2011 22:05:33 +0200
References <83822ecb-3643-42c6-a2bf-0187c07d351d@a10g2000yqn.googlegroups.com> <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host p3ee2f064.dip.t-dialin.net
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.4) Gecko/20100608 Thunderbird/3.1
In-Reply-To <6f4283c7-794c-41f1-93fd-6d9be73894c2@w11g2000vbp.googlegroups.com>
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.2261.1313311210.1164.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1313311210 news.xs4all.nl 23943 [2001:888:2000:d::a6]:47978
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:11373

Show key headers only | View raw


Am 13.08.2011 21:26, schrieb MrPink:
> 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?
>
There is. Only not in one step, if you want a date and not a datetime 
instance:

 >>> import datetime
 >>> oDateTime = datetime.datetime.strptime('07/27/2011', '%m/%d/%Y')
 >>> oDateTime
datetime.datetime(2011, 7, 27, 0, 0)
 >>> oDate = oDateTime.date()
 >>> oDate
datetime.date(2011, 7, 27)
 >>>

HTH
Sibylle

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