Add/Subtract Minutes to/from a date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jld730
    New Member
    • Apr 2007
    • 34

    Add/Subtract Minutes to/from a date

    Hello All,

    I am very new to Python and Oracle, and I have a question for you all. How do you add/subtract minutes to a date? Is this possible? I need to add/subtract 30 minutes (or 60, or 90, etc) to/from a user-defined date-and-time, and then select based on that date-and-time-range. So, if I have a date looking like '2002-03-14 17:42:00', 'YYYY-MM-DD HH24:MI:SS', is there a way to add 30 minutes to it to get the right-side of the time range, etc (as in '...17:12:00' to '...18:12:00')?

    Thanks in advance for any guidance!
  • ghostdog74
    Recognized Expert Contributor
    • Apr 2006
    • 511

    #2
    Originally posted by jld730
    Hello All,

    I am very new to Python and Oracle, and I have a question for you all. How do you add/subtract minutes to a date? Is this possible? I need to add/subtract 30 minutes (or 60, or 90, etc) to/from a user-defined date-and-time, and then select based on that date-and-time-range. So, if I have a date looking like '2002-03-14 17:42:00', 'YYYY-MM-DD HH24:MI:SS', is there a way to add 30 minutes to it to get the right-side of the time range, etc (as in '...17:12:00' to '...18:12:00')?

    Thanks in advance for any guidance!
    you can refer to the time module. here's an example
    Code:
    >>> import time
    >>> c = time.strptime("2002-03-14 17:42:00","%Y-%m-%d %H:%M:%S")
    >>> t = time.mktime(c)
    >>> t
    1016098920.0
    >>> t = t + 1800 #30 minutes is 1800 secs
    >>> t
    1016100720.0
    >>> time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(t))
    '2002-03-14 18:12:00'

    Comment

    • jld730
      New Member
      • Apr 2007
      • 34

      #3
      Awesome!! Thank-you, thank-you, thank-you! That works!

      Comment

      Working...