Re: Difference Between Two datetimes

2010-01-14 Thread Steve Ferg
I'd like to start with two dates as strings, as 1961/06/16 04:35:25 and 1973/01/18 03:45:50 How do I get the strings into a shape that will accommodate a difference? Pyfdate http://www.ferg.org/pyfdate/index.html has a numsplit function that should do the trick:

Re: Difference Between Two datetimes

2009-12-29 Thread Peter Otten
W. eWatson wrote: This is quirky. t1=datetime.datetime.strptime(20091205_221100,%Y%m%d_%H%M%S) t1 datetime.datetime(2009, 12, 5, 22, 11) type(t1) type 'datetime.datetime' t1: 2009-12-05 22:11:00 type 'datetime.datetime' but in the program: import datetime

Re: Difference Between Two datetimes

2009-12-29 Thread W. eWatson
This is quirky. t1=datetime.datetime.strptime(20091205_221100,%Y%m%d_%H%M%S) t1 datetime.datetime(2009, 12, 5, 22, 11) type(t1) type 'datetime.datetime' t1: 2009-12-05 22:11:00 type 'datetime.datetime' but in the program: import datetime

Re: Difference Between Two datetimes

2009-12-29 Thread W. eWatson
Peter Otten wrote: W. eWatson wrote: This is quirky. t1=datetime.datetime.strptime(20091205_221100,%Y%m%d_%H%M%S) t1 datetime.datetime(2009, 12, 5, 22, 11) type(t1) type 'datetime.datetime' t1: 2009-12-05 22:11:00 type 'datetime.datetime' but in the program: import datetime

Re: Difference Between Two datetimes

2009-12-29 Thread Steve Holden
W. eWatson wrote: Peter Otten wrote: W. eWatson wrote: This is quirky. t1=datetime.datetime.strptime(20091205_221100,%Y%m%d_%H%M%S) t1 datetime.datetime(2009, 12, 5, 22, 11) type(t1) type 'datetime.datetime' t1: 2009-12-05 22:11:00 type 'datetime.datetime' but in the

Re: Difference Between Two datetimes

2009-12-29 Thread M.-A. Lemburg
W. eWatson wrote: According to one web source, this program: import datetime bree = datetime.datetime(1981, 6, 16, 4, 35, 25) nat = datetime.datetime(1973, 1, 18, 3, 45, 50) difference = bree - nat print There were, difference, minutes between Nat and Bree yields: There were 3071

Re: Difference Between Two datetimes

2009-12-29 Thread Stephen Hansen
On Tue, Dec 29, 2009 at 7:21 AM, M.-A. Lemburg m...@egenix.com wrote: If you want a more human readable, relative format use Age(): Age(bree, nat) RelativeDateTime instance for '(+0008)-(+04)-(+29) HH:(+49):(+35)' at 0x2b99c6e37ef0 i.e. 8 years, 4 months, 29 days, 49 minutes, 35 seconds.

Re: Difference Between Two datetimes

2009-12-28 Thread Roy Smith
In article hh9dmv$f9...@news.eternal-september.org, W. eWatson wolftra...@invalid.com wrote: t1=datetime.datetime.strptime(2009/01/02 13:01:15,%y/%m/%d %H:%M:%S) doesn't do it. ValueError: time data did not match format: data=2009/01/02 13:01:15 fmt=%y/%m/%d %H:%M:%S The first thing that

Re: Difference Between Two datetimes

2009-12-28 Thread W. eWatson
BTW, all times are local to my city. Same time zone. -- http://mail.python.org/mailman/listinfo/python-list

Re: Difference Between Two datetimes

2009-12-28 Thread W. eWatson
Lie Ryan wrote: On 12/28/2009 5:42 PM, W. eWatson wrote: You're right. Y. Works fine. The produces datetime.datetime(2009, 1, 2, 13, 1, 15). If I now use t2=datetime.datetime.strptime(2009/01/04 13:01:15,%Y/%m/%d %H:%M:%S) I get tw as datetime.datetime(2009, 1, 4, 13, 1, 15) Then t2-t1 gives,

Re: Difference Between Two datetimes

2009-12-28 Thread Ben Finney
W. eWatson wolftra...@invalid.com writes: Lie Ryan wrote: what's strange about it? the difference between 2009/01/02 13:01:15 and 2009/01/04 13:01:15 is indeed 2 days... Can you elaborate what do you mean by 'strange'? Easily. In one case, it produces a one argument funcion, and the

Re: Difference Between Two datetimes

2009-12-28 Thread Lie Ryan
On 12/29/2009 1:12 AM, Roy Smith wrote: Hint #3: If you don't pay attention to this, you will be bitten twice a year. Not really. Some areas don't have DST and the answer to that is always exactly 5 months. -- http://mail.python.org/mailman/listinfo/python-list

Re: Difference Between Two datetimes

2009-12-28 Thread W. eWatson
Roy Smith wrote: In article hh9k6g$pk...@news.eternal-september.org, W. eWatson wolftra...@invalid.com wrote: BTW, all times are local to my city. Same time zone. Yes, but how much time has elapsed between 2009/0/04 13:01:15 and 2009/06/04 13:01:15? Even if I tell you that both timestamps

Re: Difference Between Two datetimes

2009-12-28 Thread D'Arcy J.M. Cain
On Mon, 28 Dec 2009 08:20:28 -0800 W. eWatson wolftra...@invalid.com wrote: Sort of the opposite of a stopped clock. It's right twice a day. How does one solve the DST problem? Depends on which DST problem you have. There is more than one solution depending on what the problem is. Store and

Re: Difference Between Two datetimes

2009-12-28 Thread W. eWatson
D'Arcy J.M. Cain wrote: On Mon, 28 Dec 2009 08:20:28 -0800 W. eWatson wolftra...@invalid.com wrote: Sort of the opposite of a stopped clock. It's right twice a day. How does one solve the DST problem? Depends on which DST problem you have. There is more than one solution depending on what

Re: Difference Between Two datetimes

2009-12-28 Thread W. eWatson
Ben Finney wrote: W. eWatson wolftra...@invalid.com writes: Lie Ryan wrote: what's strange about it? the difference between 2009/01/02 13:01:15 and 2009/01/04 13:01:15 is indeed 2 days... Can you elaborate what do you mean by 'strange'? Easily. In one case, it produces a one argument

Re: Difference Between Two datetimes

2009-12-28 Thread Roy Smith
In article hh9k6g$pk...@news.eternal-september.org, W. eWatson wolftra...@invalid.com wrote: BTW, all times are local to my city. Same time zone. Yes, but how much time has elapsed between 2009/0/04 13:01:15 and 2009/06/04 13:01:15? Even if I tell you that both timestamps were done in the

Re: Difference Between Two datetimes

2009-12-28 Thread Roy Smith
In article roy-2455bd.09122528122...@news.panix.com, Roy Smith r...@panix.com wrote: Yes, but how much time has elapsed between 2009/0/04 13:01:15 Typo. Should be 2009/01/04 13:01:15. -- http://mail.python.org/mailman/listinfo/python-list

Re: Difference Between Two datetimes

2009-12-28 Thread Steven D'Aprano
On Mon, 28 Dec 2009 23:50:30 +1100, Ben Finney wrote: How does one unload this structure to get the seconds and days? It's customary to consult the documentation for questions like that URL:http://docs.python.org/library/datetime.html#datetime.timedelta. No no no, it's customary to annoy

Re: Difference Between Two datetimes

2009-12-28 Thread Peter Otten
W. eWatson wrote: Peter Otten wrote: W. eWatson wrote: This is quirky. t1=datetime.datetime.strptime(20091205_221100,%Y%m%d_%H%M%S) t1 datetime.datetime(2009, 12, 5, 22, 11) type(t1) type 'datetime.datetime' t1: 2009-12-05 22:11:00 type 'datetime.datetime' but in the

Re: Difference Between Two datetimes

2009-12-28 Thread Steven D'Aprano
On Mon, 28 Dec 2009 10:54:46 -0800, W. eWatson wrote: Ben Finney wrote: W. eWatson wolftra...@invalid.com writes: Lie Ryan wrote: what's strange about it? the difference between 2009/01/02 13:01:15 and 2009/01/04 13:01:15 is indeed 2 days... Can you elaborate what do you mean by

Re: Difference Between Two datetimes

2009-12-28 Thread Steven D'Aprano
On Mon, 28 Dec 2009 14:42:21 -0800, W. eWatson wrote: So as long as I don't print it, it's datetime.datetime and I can make calculations or perform operations on it as though it is not a string, but a datetime object? No, it remains a datetime object regardless of whether you print it or

Re: Difference Between Two datetimes

2009-12-28 Thread Steven D'Aprano
On Mon, 28 Dec 2009 23:22:09 +0100, Peter Otten wrote: print some_object first converts some_object to a string invoking str(some_object) which in turn calls the some_object.__str__() method. The resulting string is then written to stdout. In fairness to the OP, that's a misleading way of

Re: Difference Between Two datetimes

2009-12-28 Thread W. eWatson
Steven D'Aprano wrote: On Mon, 28 Dec 2009 23:50:30 +1100, Ben Finney wrote: How does one unload this structure to get the seconds and days? It's customary to consult the documentation for questions like that URL:http://docs.python.org/library/datetime.html#datetime.timedelta. No no no,

Re: Difference Between Two datetimes

2009-12-28 Thread Ben Finney
W. eWatson wolftra...@invalid.com writes: It doesn't seem to be standard practice to more or less teach the environment that Python is in. If they do, it's jumbled around. Most books start with Python itself and skirt the issues of the environment and interaction. There are no Python

Re: Difference Between Two datetimes

2009-12-27 Thread Stephen Hansen
On Sun, Dec 27, 2009 at 8:54 PM, W. eWatson wolftra...@invalid.com wrote: That's fine, but I'd like to start with two dates as strings, as 1961/06/16 04:35:25 and 1973/01/18 03:45:50 How do I get the strings into a shape that will accommodate a difference? For example,

Re: Difference Between Two datetimes

2009-12-27 Thread Ben Finney
W. eWatson wolftra...@invalid.com writes: How do I get the strings into a shape that will accommodate a difference? For example, t1=datetime.datetime.strptime(2009/01/02 13:01:15,%y/%m/%d %H:%M:%S) doesn't do it. ValueError: time data did not match format: data=2009/01/02 13:01:15

Re: Difference Between Two datetimes

2009-12-27 Thread W. eWatson
You're right. Y. Works fine. The produces datetime.datetime(2009, 1, 2, 13, 1, 15). If I now use t2=datetime.datetime.strptime(2009/01/04 13:01:15,%Y/%m/%d %H:%M:%S) I get tw as datetime.datetime(2009, 1, 4, 13, 1, 15) Then t2-t1 gives, datetime.timedelta(2) which is a 2 day difference--I guess.

Re: Difference Between Two datetimes

2009-12-27 Thread W. eWatson
Ben Finney wrote: W. eWatson wolftra...@invalid.com writes: How do I get the strings into a shape that will accommodate a difference? For example, t1=datetime.datetime.strptime(2009/01/02 13:01:15,%y/%m/%d %H:%M:%S) doesn't do it. ValueError: time data did not match format: data=2009/01/02

Re: Difference Between Two datetimes

2009-12-27 Thread Lie Ryan
On 12/28/2009 5:42 PM, W. eWatson wrote: You're right. Y. Works fine. The produces datetime.datetime(2009, 1, 2, 13, 1, 15). If I now use t2=datetime.datetime.strptime(2009/01/04 13:01:15,%Y/%m/%d %H:%M:%S) I get tw as datetime.datetime(2009, 1, 4, 13, 1, 15) Then t2-t1 gives,