Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

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

Question posted by: pugalenthi (Member) on May 12th, 2008 07:22 PM
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.5000000

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.
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
TheServant's Avatar
TheServant
Needs Regular Fix
462 Posts
May 13th, 2008
02:56 AM
#2

Re: How to perform this data type conversion and following it up with SUM operation?.
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.

Reply
Atli's Avatar
Atli
Moderator
2,166 Posts
May 13th, 2008
07:56 AM
#3

Re: How to perform this data type conversion and following it up with SUM operation?.
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.

Reply
Reply
Not the answer you were looking for? Post your question . . .
182,371 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top PHP Forum Contributors