How to perform this data type conversion and following it up with SUM operation?.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pugalenthi
    New Member
    • Jan 2007
    • 44

    How to perform this data type conversion and following it up with SUM operation?.

    I get data from a MS SQL table. The data has a data type of nchar. A sample data is as follows,

    00:00:01.500000 0

    The above data represents Hrs:Mins:Secs

    Now i need to convert this data into a suitable data type so that i can add all such related data. After adding i will get total hrs, mins and secs. How can i do this. Please provide some ideas.
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    You will need to separate that data (reg expressions) into the different components (day, month, year, hour, minute and seconds) and then use a function like mktime() to convert it to a time stamp. Once it is in that form you can add or subtract. Once you have done what you wanted, you can convert it back to date format using the date() function.

    Hope that helps.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi.

      Once your data is available to your PHP code, the simplest way to parse this into something useful would be to use the explode function to split it up into hours, minutes and seconds, and then use it again to split the seconds and milliseconds.

      Although, it would probably be cleaner to use a regular expression via the preg_match function.

      Comment

      Working...