473,385 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

datetime and strptime

Hi,

it seems the datetime library does not have a .strptime class method.
If I want to create a datetime object from a string, I currently have to do:

datetime.date(*time.strptime(s, "%Y%m%d")[:3])

If the format is more complex (not in the order of a timetuple), it is
even more complicated. In my opinion, it would be better to be able to do:

datetime.date.strptime(s, "%Y%m%d")

Is there a particular reason that this is not possible?
Or is the only reason that it hasn't been implemented?

yours,
Gerrit, who wanted to write a patch until he saw datetime is written in C.

--
233. If a builder build a house for some one, even though he has not
yet completed it; if then the walls seem toppling, the builder must make
the walls solid from his own means.
-- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Kom in verzet tegen dit kabinet:
http://www.sp.nl/

Jul 18 '05 #1
5 12751
In article <ma************************************@python.org >, Gerrit
Holl wrote:
Hi,

it seems the datetime library does not have a .strptime class method.

[snip]

Have a look at PEP 321:

http://www.python.org/peps/pep-0321.html

It seems to describe one possible future for the parsing capabilities
of datetime. Under "Generic Input Parsing" the following question is
posed: "Is a strptime() implementation that returns datetime types
sufficient?" No clear answer, though.

--
Magnus Lie Hetland "In this house we obey the laws of
http://hetland.org thermodynamics!" Homer Simpson
Jul 18 '05 #2
Magnus Lie Hetland wrote:
In article <ma************************************@python.org >, Gerrit
Holl wrote:
Hi,

it seems the datetime library does not have a .strptime class method.

[snip]

Have a look at PEP 321:

http://www.python.org/peps/pep-0321.html


Ah, yes...
Thanks for the link!

yours,
Gerrit.

--
167. If a man marry a wife and she bear him children: if this wife die
and he then take another wife and she bear him children: if then the
father die, the sons must not partition the estate according to the
mothers, they shall divide the dowries of their mothers only in this way;
the paternal estate they shall divide equally with one another.
-- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Kom in verzet tegen dit kabinet:
http://www.sp.nl/

Jul 18 '05 #3
Magnus Lie Hetland <ml*@furu.idi.ntnu.no> wrote:
In article <ma************************************@python.org >, Gerrit
Holl wrote:
Hi,

it seems the datetime library does not have a .strptime class method.

[snip]

Have a look at PEP 321:

http://www.python.org/peps/pep-0321.html

It seems to describe one possible future for the parsing capabilities
of datetime. Under "Generic Input Parsing" the following question is
posed: "Is a strptime() implementation that returns datetime types
sufficient?" No clear answer, though.


I see that PEP targets Python 2.4. If the PEP is accepted and
implemented, I for one would love to see the implementation back-ported
to a 2.3.x patch release. This is something I also (briefly) considered
doing; unfortunately, I can't see myself having any time for this in the
foreseeable future...

--
Robin Munn
rm***@pobox.com
Jul 18 '05 #4
On Wed, 19 Nov 2003 17:09:31 GMT,
Robin Munn <rm***@pobox.com> wrote:
I see that PEP targets Python 2.4. If the PEP is accepted and
implemented, I for one would love to see the implementation back-ported
to a 2.3.x patch release. This is something I also (briefly) considered


The rule for patch releases is "no new features, only bugfixes", so it would
be very difficult to bend the rules for this one method. If the
implementation is just a Python module, though, it would be possible for
someone to package the module for use with 2.3.

--amk
Jul 18 '05 #5
Robin Munn <rm***@pobox.com> wrote in message news:<sl******************@rmunnlfs.dyndns.org>...
[ adding datetime.strptime() ]
I see that PEP targets Python 2.4. If the PEP is accepted and
implemented, I for one would love to see the implementation back-ported
to a 2.3.x patch release. This is something I also (briefly) considered
doing; unfortunately, I can't see myself having any time for this in the
foreseeable future...


Absolutely not. Patch releases are for bugfixes only, not new features.
And yes, I'm aware that adding the boolean hackage to 2.2.x broke this
rule, but that was very much the exception rather than the rule.

Based on the feedback from the recent 2.3 releases, one thing that was
appreciated by many people was that there were no new features, or changes
that could break running code. This allows people with production systems
to happily upgrade without fearing for their sanity.
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Martin Bless | last post by:
Below is what I'm currently using to construct datatime objects from strings. Date and time objects are made up similar. To and from string conversions are frequently needed in SQL neighborhood. ...
0
by: josh | last post by:
Shouldn't datetime have strptime? It already has strftime, and it'd be really nice to obviate datetime.fromtimestamp(time.mktime(time.strptime(...))) thanks in advance
2
by: Samuel | last post by:
Hello, I am trying to convert a local time into UTC ISO8601, then parse it back into local time. I tried the following: ---------------------- #!/usr/bin/python import time import datetime...
1
by: Douglas Douglas | last post by:
Hi everybody. I need to create a datetime object from a string like "20/01/2005 15:10:01". I know the mxDateTime module can do this with the DateTimeFrom method, but I was wondering if is...
5
by: Brendan | last post by:
Hi All I can't find the "Python Way" of writing a datetime instance to a string so that it can be easily parsed back again. time.strptime is apparantly not supported on some platforms, and...
29
by: dyork | last post by:
When getting data from a database using the dbapi and an SQL query, how do you in general round trip the data? Especially date-time? An SQL datetime column translates nicely into a Python...
5
by: rouven | last post by:
Hi, i am trying to convert that time format '05:26:40 Jun 19, 2007 PDT' into mysql compatible format like YYYY-MM-DD HH:MM:SS. the code i tried was: from datetime import datetime from time...
1
by: Christian Heimes | last post by:
Rick King schrieb: datetime.date is a C extension class. Subclassing of extension classes may not always work as you'd expect it. Christian
4
by: Laszlo Nagy | last post by:
def str2datetime(s): #28 May 2008 12:38:16 BDT return time.strptime(s,"%d %b %Y %H:%M:%S %Z") #.... some code here.... print repr(pd) print str2datetime(pd) Result:
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.