Adding Time

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vivekjain
Forum Commoner
Posts: 76
Joined: Thu Jan 08, 2004 12:38 am

Adding Time

Post by vivekjain »

Hi,
Can you tell how do I add time, i.e.

Start time ----------------- End Time ---------------- ---- Total

12:00:09 PM ---------------- 12:07:59 PM ---------------- 0:07:50

12:10:32 PM ---------------- 2:25:04 PM ---------------- 1:34:32



There are many more records and I want to add the Totals, including the seconds, minutes and hours.

Can anyone suggest how I could do that using PHP.

Thanks
127.0.0.1
Forum Newbie
Posts: 22
Joined: Mon Sep 12, 2005 8:59 pm

Post by 127.0.0.1 »

Depending on the way you require this to work you may be able to use the function mktime.

http://uk.php.net/mktime
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

convert them to unix timestamps, add them up, divide it back out into the apporpriate format if you are using php to do it. If you're using a database, they often have date/time interaction functions. For instance, MySQL has ADDTIME(). Note that you shouldn't use 12 hour format times with MySQL..
Post Reply