Time conversion function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • artistlikeu
    New Member
    • Nov 2006
    • 38

    #1

    Time conversion function

    I have time column in my database whose data type is "time" i.e 00:00:00.
    In python i make a query and get this column as string.
    I want this time only in seconds i.e. integers.

    I want a python function which converts time like this into seconds (integers).
    Presently i am writing formula in python But Is there any function which serves this purpose????
    What i have to do???
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by artistlikeu
    I have time column in my database whose data type is "time" i.e 00:00:00.
    In python i make a query and get this column as string.
    I want this time only in seconds i.e. integers.

    I want a python function which converts time like this into seconds (integers).
    Presently i am writing formula in python But Is there any function which serves this purpose????
    What i have to do???
    This simple function will return the time in seconds as an integer:
    Code:
    def time_in_seconds(time_str):
        str_list = (time_str.split(":"))
        return int(str_list[0])*3600 + int(str_list[1])*60 + int(str_list[2])

    Comment

    • artistlikeu
      New Member
      • Nov 2006
      • 38

      #3
      Hi all,
      i do not want to define time class....... i want to write or add a function for time that convers time into seconds and give me integers

      cheers...










      Originally posted by bvdet
      This simple function will return the time in seconds as an integer:
      Code:
      def time_in_seconds(time_str):
          str_list = (time_str.split(":"))
          return int(str_list[0])*3600 + int(str_list[1])*60 + int(str_list[2])

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by artistlikeu
        Hi all,
        i do not want to define time class....... i want to write or add a function for time that convers time into seconds and give me integers

        cheers...
        This defines a function, not a class. Look at the docs [Global Module Index -> time] for time related classes.

        If you are using a SQL database, I can help you get the second from there.

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          Originally posted by bvdet
          This simple function will return the time in seconds as an integer:
          Code:
          def time_in_seconds(time_str):
          str_list = (time_str.split(":"))
          return int(str_list[0])*3600 + int(str_list[1])*60 + int(str_list[2])
          Thanks for hanging around. I have ideas for making this forum a place where more expert topics are discussed.
          Stick around,
          Barton

          Comment

          Working...