#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    38
    Rep Power
    12

    date function question


    I would like to add 12 hours to a the current date...

    1) I dont even know what to call to get current date....

    date()??? I know I can import time and do time.time() to get a time value but what do I import ?? to utilize a "date()" function.

    2) Once I know how to get a current date into a local variable. How do I increment that date by 12 hours.

    thanks
    Penngray
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    38
    Rep Power
    12
    version 2.2.3 of python
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Obviously you've discovered the time module.. in python 2.3 you could have also used the timedate module . Anyway give this a try

    >>> import time
    >>> time.localtime()
    (2003, 10, 3, 18, 43, 29, 4, 276, 1)
    >>> time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime(time.time() + 43200))
    'Sat, 04 Oct 2003 06:59:55'

    Ok so we know there are 60 seconds in a minuite, so if we multiply that by 60 we get the number of seconds in an hour (3600). If we then times that by the number of hours we want to add to the time we get 43200. Then we can add that to the current time and use the strftime() function to format the new time

    Have fun,
    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo