473,414 Members | 1,766 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,414 software developers and data experts.

ISO to Gregorian, strptime madness


Can I easily convert from ISO to Gregorian calendars in Python 2.3?

For example, what Gregorian date is year 2004, week 1, day 1?

If possible, I'd greatly prefer to do this with the standard library.
I believe the mx.DateTime module provides this functionality, but I've
spent a bit of time converting pre-2.3 code to the new datetime modules.

---

While I'm posting, how about this old dilemma... from the 2.3 modules.
strptime exists in time, but not in datetime, while strftime exists in
both. So, to strptime into a datetime, I am forced to use * like so :

t1tmp = time.strptime(sometext,timeformat)
t1 = datetime.datetime(*t1tmp[0:6])

My question is, is there a better way which might be closer to something
like datetime.strptime? (which doesn't exist strangely).

---

-AB
Jul 18 '05 #1
4 3444
Afanasiy wrote:

While I'm posting, how about this old dilemma... from the 2.3 modules.
strptime exists in time, but not in datetime, while strftime exists in
both.


Uh, really?

C:\>python23
Python 2.3.2 (#49, Oct 2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on win32
import time
import datetime
time.strftime <built-in function strftime> time.strptime <built-in function strptime> datetime.strftime Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute 'strftime' datetime.strptime

Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute 'strptime'
Looks to me like strptime and strftime are both in time and not in datetime.

-Peter
Jul 18 '05 #2
On Thu, 04 Dec 2003 10:43:38 -0500, Peter Hansen <pe***@engcorp.com>
wrote:
Afanasiy wrote:

While I'm posting, how about this old dilemma... from the 2.3 modules.
strptime exists in time, but not in datetime, while strftime exists in
both.


Uh, really?

Looks to me like strptime and strftime are both in time and not in datetime.


Yeah I didn't remember the specifics, but it's something like that.
Something that I needed to have strptime does not have it, but has
strftime. I am a sorry for that mistake now, because of your reply.

This is not the primary concern of the post, and not even secondary,
so please ignore the silly mistake and help with the other things.
Jul 18 '05 #3
On Thu, 04 Dec 2003 10:43:38 -0500, Peter Hansen <pe***@engcorp.com>
wrote:
Afanasiy wrote:

While I'm posting, how about this old dilemma... from the 2.3 modules.
strptime exists in time, but not in datetime, while strftime exists in
both.
Uh, really?


Ok, I checked it out, even though it's not my primary concern.
Looks to me like strptime and strftime are both in time and not in datetime.


datetime the class in the datetime module has strftime but no strptime
datetime.datetime.strftime <method 'strftime' of 'datetime.date' objects> datetime.datetime.strptime Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: type object 'datetime.datetime' has no attribute
'strptime'


So... I do this sort of thing :

t1tmp = time.strptime(sometext,timeformat)
t1 = datetime.datetime(*t1tmp[0:6])

-AB

Jul 18 '05 #4
Afanasiy wrote:

On Thu, 04 Dec 2003 10:43:38 -0500, Peter Hansen <pe***@engcorp.com>
wrote:
Afanasiy wrote:

While I'm posting, how about this old dilemma... from the 2.3 modules.
strptime exists in time, but not in datetime, while strftime exists in
both.


Uh, really?

Looks to me like strptime and strftime are both in time and not in datetime.


Yeah I didn't remember the specifics, but it's something like that.
Something that I needed to have strptime does not have it, but has
strftime. I am a sorry for that mistake now, because of your reply.

This is not the primary concern of the post, and not even secondary,
so please ignore the silly mistake and help with the other things.


I wish I could help, but I don't know anything about this area. I was
just struck by the seeming irregularity, but upon investigating I didn't
see the same thing you did so I pointed it out.

(To be honest, I don't see the problem with a two-line solution, which
could easily be encapsulated in a simple function if it looks too
ugly for you.)

-Peter
Jul 18 '05 #5

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

Similar topics

4
by: Henk-Jan de Jong | last post by:
Hello all, I'm completely new in Python and have the next problem. I have a huge file with dates a want to convert from one format to another. e.g 31-12-2003 should become 31122003. I'm using...
5
by: Gerrit Holl | last post by:
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,...
1
by: Michele Simionato | last post by:
I have strings representing UTC dates and I want to convert them in time tuples using time.strptime. I have an issue with daylight savings. For instance Tue Sep 14 06:06:15 2004 is converted...
2
by: Robert | last post by:
A certain DAV server reports a time stamp as "Tues, 30 Aug 2005 20:48:31" ( but not "Tue, ..." as usual) This produces the error below. >>> time.strptime("Tue, 30 Aug 2005 20:48:31","%a, %d...
5
by: SalimShahzad | last post by:
Dear Respected Gurus, I need a coding assistant converting from gregorian to hijri and vice versa. I have problem with this codes. the problem Gregorian to Hijri gives 100% results. when i enter...
4
by: kongkolvyu | last post by:
Hi The strptime function works just fine on Solaris. Here is an example on how I use it: struct tm tmpTm; if(strptime("20010101010101","%Y%m%d%H%M%S",&tmpTm)==NULL) printf("Error,String convert...
4
by: Maximilian Michel | last post by:
Hi all, I have an interesting problem: I have written code, that reads a logfile and parses it for date string (Thu Jun 29 14:01:23 2006). Standalone everthing works fine, all is recognized. ...
3
by: Tom Anderson | last post by:
Hello! Possibly i'm missing something really obvious here. But ... If i have a date-time string of the kind specified in RFC 1123, like this: Tue, 12 Aug 2008 20:48:59 -0700 Can i turn...
3
by: W. eWatson | last post by:
Apparently, use of strptime of datetime needs a workaround in Python 2.4 to work properly. The workaround is d = datetime.datetime(*(time.strptime(date_string, format))). However, when I try to...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.