[Zope] Subtracting 2 dates from each other
Peter Bengtsson
mail@peterbe.com
Mon, 28 May 2001 16:34:25 +0200
The you can easyly find out the number of hours, days and seconds there are
between two dates (like I showed you below). The only tricky thing is to
make it back to a datetime.
date1 = DateTime('2001/05/25 20:30:00')
date2 = DateTime('2001/05/25 19:00:00')
days = (date1 - date2)
hours = (days)*24
minutes = (hours)*60
seconds = (minutes)*60
weeks = (days)/7
Aren't these variables enough?
Do you want to create a valid DateTime object "back" from these
calculations?
To do that you need to use a reference date. Like today or date1 or
something.
More help?
Peter
----- Original Message -----
From: "Gitte Wange" <gitte@mmmanager.org>
To: "Peter Bengtsson" <mail@peterbe.com>; "Tino Wildenhain"
<tino@wildenhain.de>
Cc: <zope@zope.org>
Sent: Monday, May 28, 2001 3:16 PM
Subject: Re: [Zope] Subtracting 2 dates from each other
> On Monday 28 May 2001 15:18, Peter Bengtsson wrote:
> > What do you really want?
> >
> > >>> from DateTime import DateTime
> > >>> date1 = DateTime('2001/05/25 20:30:00')
> > >>> date2 = DateTime('2001/05/25 19:00:00')
> > >>> res = date1 - date2
> > >>> type(res)
> >
> > <type 'float'>
> >
> > >>> hours = res*24
> > >>> type(hours)
> >
> > <type 'float'>
> >
> > >>> print hours
> >
> > 1.5
> >
> > Do you want to calculate how many hours there are between two dates? Or
how
> > many days (like 'res' above)?
> > If your result is unchanging even though you change the dates, could it
be
> > because you're doing some int() roundoff or something so that you loose
the
> >
> > accuracy in the hours; like this:
> > >>> print int(res*24)
> >
> > 1
> >
> > Peter
>
> I want to know EXTACTLY how long time (in hours, minutes, seconds) there
is
> between Date1 and Date2 ...
>
> Anyone ???
>
> Gitte
>
> >
> > ----- Original Message -----
> > From: "Gitte Wange" <gitte@mmmanager.org>
> > To: "Tino Wildenhain" <tino@wildenhain.de>
> > Cc: <zope@zope.org>
> > Sent: Monday, May 28, 2001 2:12 PM
> > Subject: Re: [Zope] Subtracting 2 dates from each other
> >
> > > On Monday 28 May 2001 14:04, you wrote:
> > > > Hi Gitte,
> > > >
> > > > how about Date1 - Date2 ? :)
> > > >
> > > > Of course they must be DateTime instances, not strings.
> > > >
> > > > Regards
> > > > Tino
> > >
> > > That doesn't work ..
> > > Well it subtracts something .... but the result is very weird.
> > > An example:
> > > Date1 = 2001/05/25 20:30:00
> > > Date2 = 2001/05/25 19:00:00
> > >
> > > Expected result: 01:30:00
> > > The result I got: 01:00:00
> > >
> > > And changing the dates doesn't change the result ... why ???
> > >
> > > Gitte
> > >
> > > > --On Montag, 28. Mai 2001 08:15 +0200 Gitte Wange
<gitte@mmmanager.org>
> > > >
> > > > wrote:
> > > > > Hello,
> > > > >
> > > > > I need to subtract to dates from each other.
> > > > > I have searched the archives but haven't found anything useful.
> > > > > Hope someone here could help me.
> > > > >
> > > > > Regards,
> > > > > --
> > > > > ************************
> > > > > Gitte Wange Jensen
> > > > >
> > > > > System Squid Developer
> > > > > MMManager Aps
> > > > > +45 29 72 79 72
> > > > >
> > > > > gitte@mmmanager.org
> > > > > ************************
> > > > >
> > > > > _______________________________________________
> > > > > Zope maillist - Zope@zope.org
> > > > > http://lists.zope.org/mailman/listinfo/zope
> > > > > ** No cross posts or HTML encoding! **
> > > > > (Related lists -
> > > > > http://lists.zope.org/mailman/listinfo/zope-announce
> > > > > http://lists.zope.org/mailman/listinfo/zope-dev )
> > >
> > > _______________________________________________
> > > Zope maillist - Zope@zope.org
> > > http://lists.zope.org/mailman/listinfo/zope
> > > ** No cross posts or HTML encoding! **
> > > (Related lists -
> > > http://lists.zope.org/mailman/listinfo/zope-announce
> > > http://lists.zope.org/mailman/listinfo/zope-dev )