need a little help with time

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nephish@xit.net

    #1

    need a little help with time

    Hey there.
    i have a time string (created with strftime) then read from a file,
    i am having some trouble understanding how to get the difference
    between times.
    i know i can structime(times tring) and get a time value, but i dont
    know how to manipulate it.

    basically, if i have string 2005-08-24 09:25:58
    and another string 2005-08-24 09:28:58

    how can i tell how many minutes, hours, seconds, days, months etc..
    have passed between the first string and the second ?

    or, if there is a good tutorial on this kind of thing, please post a
    url.

    thanks

    shawn

  • Diez B. Roggisch

    #2
    Re: need a little help with time

    nephish@xit.net wrote:[color=blue]
    > Hey there.
    > i have a time string (created with strftime) then read from a file,
    > i am having some trouble understanding how to get the difference
    > between times.
    > i know i can structime(times tring) and get a time value, but i dont
    > know how to manipulate it.
    >
    > basically, if i have string 2005-08-24 09:25:58
    > and another string 2005-08-24 09:28:58
    >
    > how can i tell how many minutes, hours, seconds, days, months etc..
    > have passed between the first string and the second ?
    >
    > or, if there is a good tutorial on this kind of thing, please post a
    > url.[/color]

    Look at the module datetime.

    Diez

    Comment

    • Eddie Corns

      #3
      Re: need a little help with time

      nephish@xit.net writes:
      [color=blue]
      >Hey there.
      >i have a time string (created with strftime) then read from a file,
      >i am having some trouble understanding how to get the difference
      >between times.
      >i know i can structime(times tring) and get a time value, but i dont
      >know how to manipulate it.[/color]
      [color=blue]
      >basically, if i have string 2005-08-24 09:25:58
      >and another string 2005-08-24 09:28:58[/color]
      [color=blue]
      >how can i tell how many minutes, hours, seconds, days, months etc..
      >have passed between the first string and the second ?[/color]
      [color=blue]
      >or, if there is a good tutorial on this kind of thing, please post a
      >url.[/color]

      Either the datetime module or mxDateTime from
      Provides the most natural and robust way of dealing with date/time values in Python.

      which is more extensive.

      Comment

      • nephish@xit.net

        #4
        Re: need a little help with time

        the mxDateTime thing should be great, i have to pass this stuff back
        and forth with MySQL DateTime fields,
        thanks a lot !

        Comment

        • Randy Bush

          #5
          Re: need a little help with time

          i am doing disgusting looking junk based on calendar. example

          now = calendar.timegm (time.gmtime())
          aWeek = 7*24*60*60
          print time.strftime(' %Y-%m-%d %H:%M:%S', time.gmtime(now + aWeek))

          randy

          Comment

          Working...