Thread: How to calculate date differences

1. How to calculate date differences

Hi there! Does anyone know how to calculate the difference between two dates? Say for example to get the number of days between today and a future calendar event that i've set or the number of weeks to go.

2. Re: How to calculate date differences

Here's one possibility. Should cope with leap years and is limited to dates in range accepted by mktime which should cover 1970 to 2038 at least.

Code:
```>>> d1=(2009,1,1,0,0,0,-1,-1,-1)
>>> d2=(2010,1,1,0,0,0,-1,-1,-1)
>>> t1=time.mktime(d1)
>>> t2=time.mktime(d2)
>>> days=(t2-t1)/(60*60*24)
>>> days
365.0```
It's a shame that datetime objects aren't implemented which would make the task easier.

3. Re: How to calculate date differences

Originally Posted by t-kev
Hi there! Does anyone know how to calculate the difference between two dates? Say for example to get the number of days between today and a future calendar event that i've set or the number of weeks to go.
This is a good start http://pleac.sourceforge.net/pleac_p...sandtimes.html

4. Re: How to calculate date differences

Originally Posted by mahesh.sayibabu
It's useless in this context. The date manipulation examples use the datetime object which isn't implemented in Python for the S60.

5. Re: How to calculate date differences

Originally Posted by dakin80
It's useless in this context. The date manipulation examples use the datetime object which isn't implemented in Python for the S60.
Note that it is implemented in PyS60 1.9.0 and newer (works fine on 1.9.4 at least).

6. Re: How to calculate date differences

Originally Posted by dakin80
It's useless in this context. The date manipulation examples use the datetime object which isn't implemented in Python for the S60.
As noted by bogdan.galiceanu, datetime is available from PyS60 1.9.0 onwards.

7. Re: How to calculate date differences

Sorry for being off the radar. Im using PyS60 1.4.5 and as far as I know it doesn't support the datetime object. Is there another way out of this?

8. Re: How to calculate date differences

Originally Posted by t-kev
Sorry for being off the radar. Im using PyS60 1.4.5 and as far as I know it doesn't support the datetime object. Is there another way out of this?
There is a new version of PyS60 available based on Python 2.5.4 which supports datetime module. Although this is a developer release, you can try it out -> https://garage.maemo.org/frs/?group_...elease_id=2673

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•