×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    4

    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. #2
    Registered User
    Join Date
    Dec 2008
    Posts
    6

    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. #3
    Nokia Developer Expert
    Join Date
    Apr 2007
    Posts
    131

    Re: How to calculate date differences

    Quote Originally Posted by t-kev View Post
    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. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    6

    Re: How to calculate date differences

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

  5. #5
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: How to calculate date differences

    Quote Originally Posted by dakin80 View Post
    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. #6
    Nokia Developer Expert
    Join Date
    Apr 2007
    Posts
    131

    Re: How to calculate date differences

    Quote Originally Posted by dakin80 View Post
    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. #7
    Registered User
    Join Date
    Nov 2008
    Posts
    4

    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. #8
    Regular Contributor
    Join Date
    Oct 2007
    Posts
    114

    Re: How to calculate date differences

    Quote Originally Posted by t-kev View Post
    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
    import antigravity

Similar Threads

  1. Not able to set the created SMS date ..
    By keerthi.ck06 in forum Symbian
    Replies: 10
    Last Post: 2009-05-22, 14:26
  2. Issue regarding date and time
    By himsymbian in forum Symbian
    Replies: 15
    Last Post: 2009-01-21, 10:57
  3. Date & Time Editor in Form Resource.
    By Kavit Patel in forum Symbian
    Replies: 2
    Last Post: 2008-03-03, 06:26
  4. preverify error. PLZ HELP
    By michaelhann89 in forum Mobile Java Tools & SDKs
    Replies: 14
    Last Post: 2007-03-22, 22:51
  5. Date format...!!!
    By palak_shah_23 in forum Symbian
    Replies: 4
    Last Post: 2006-09-07, 07:27

Posting Permissions

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