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: http://www.ferg.org/pyf

Re: Difference Between Two datetimes

2009-12-29 Thread Stephen Hansen
On Tue, Dec 29, 2009 at 7:21 AM, M.-A. Lemburg wrote: > If you want a more human readable, relative format use Age(): > > >>> Age(bree, nat) > 0x2b99c6e37ef0> > > i.e. 8 years, 4 months, 29 days, 49 minutes, 35 seconds. > That is... awesome. I use mx.DateTime all the time, and never knew about

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: > Ther

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) >>> >>> >>> >>> t1: 2009-12-05 22:11:00 >>> >>> but in the pr

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) >>> t1: 2009-12-05 22:11:00 but in the program: import datetime t1=datetime.datetime.strptime("2

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) >>> t1: 2009-12-05 22:11:00 but in the program: import datetime t1=datetime.datetime.strptime("20091205_221100","%Y%m%d_%H%M%S") print "t1:

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) > > >>> > t1: 2009-12-05 22:11:00 > > but in the program: > import datetime > > t1=datetime.datetime.strpt

Re: Difference Between Two datetimes

2009-12-28 Thread Ben Finney
"W. eWatson" 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 documentation police enf

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 http://docs.python.org/library/datetime.html#datetime.timedelta>. No no no, it's

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 wa

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 n

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" 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'?

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) >>> >>> >>> >>> t1: 2009-12-05 22:11:00 >>> >>> but in the

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 > 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 Roy Smith
In article , Roy Smith 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 Roy Smith
In article , "W. eWatson" 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 same city, you don't have enough information. Hint #1:

Re: Difference Between Two datetimes

2009-12-28 Thread W. eWatson
Ben Finney wrote: "W. eWatson" 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 other 2,

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" 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

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" 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 compare in UTC and

Re: Difference Between Two datetimes

2009-12-28 Thread W. eWatson
Roy Smith wrote: In article , "W. eWatson" 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 same city, you don't have enough info

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 Ben Finney
"W. eWatson" 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 other > 2, possib

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 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 Roy Smith
In article , "W. eWatson" 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 jumps out at me is that %y is the two-digit year. Y

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, datetime.timede

Re: Difference Between Two datetimes

2009-12-27 Thread W. eWatson
Ben Finney wrote: "W. eWatson" 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 fmt=%y/%m

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 gue

Re: Difference Between Two datetimes

2009-12-27 Thread Ben Finney
"W. eWatson" 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 > fmt=%y/%m/%d %H:%

Re: Difference Between Two datetimes

2009-12-27 Thread Stephen Hansen
On Sun, Dec 27, 2009 at 8:54 PM, W. eWatson 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, > t1=datetime.datetime.strptime("2

Difference Between Two datetimes

2009-12-27 Thread W. eWatson
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 days, 0:49:35 minutes betwe

Re: how to calc the difference between two datetimes?

2005-05-08 Thread Stewart Midwinter
thanks Robert, those 4 lines of code sure beat the 58 of my home-rolled time-date function! cheers S -- http://mail.python.org/mailman/listinfo/python-list

Re: how to calc the difference between two datetimes?

2005-05-08 Thread Jp Calderone
On Sun, 8 May 2005 19:06:31 -0600, Stewart Midwinter <[EMAIL PROTECTED]> wrote: >After an hour of research, I'm more confused than ever. I don't know >if I should use the time module, or the eGenix datetime module. Here's >what I want to do: I want to calculate the time difference (in >seconds wou

RE: how to calc the difference between two datetimes?

2005-05-08 Thread Robert Brewer
Stewart Midwinter wrote: > After an hour of research, I'm more confused than ever. I don't know > if I should use the time module, or the eGenix datetime module. Here's > what I want to do: I want to calculate the time difference (in > seconds would be okay, or minutes), between two date-time stri

how to calc the difference between two datetimes?

2005-05-08 Thread Stewart Midwinter
After an hour of research, I'm more confused than ever. I don't know if I should use the time module, or the eGenix datetime module. Here's what I want to do: I want to calculate the time difference (in seconds would be okay, or minutes), between two date-time strings. so: something like this: ti