mxDateTime package question

P

Prashant Pai

I have a Julian (?) date string '2000238' (format YYYYDDD) which
corresponds to 2000/08/25

How do I create a correct DateTime object with this?

thanks
 
S

Steve Holden

Prashant said:
I have a Julian (?) date string '2000238' (format YYYYDDD) which
corresponds to 2000/08/25

How do I create a correct DateTime object with this?

thanks

You could try
>>> jd = "2000238"
>>> y = int(jd[:4])
>>> d = int(jd[4:])-1
>>> yd = mx.DateTime.DateTime(y)
>>> dinc = mx.DateTime.DateTimeDeltaFromDays(d)
>>> result = yd+dinc
>>> result

but there may well be more efficient ways.

regards
Steve
 
E

Eddie Corns

I have a Julian (?) date string '2000238' (format YYYYDDD) which
corresponds to 2000/08/25
How do I create a correct DateTime object with this?

Logically you could do:
<DateTime object for '2000-08-25 00:00:00.00' at 403ae410>

However that doesn't work on all systems. Works on my Linux systems but not
my BSD ones :( Depends on the C implementation of strptime which has never
been 100%

Probably better to do:

year,day = ...
mx.DateTime.strptime(year,'%Y') + int(day) - 1

eg:
<DateTime object for '2000-08-25 00:00:00.00' at 4039c138>


which is more portable.

Eddie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top