working with hours / sum of hours

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
headbull
Forum Newbie
Posts: 10
Joined: Thu Jun 07, 2012 7:18 am

working with hours / sum of hours

Post by headbull »

I was wondering if anybody have any good ideas to working with hours/sum of hours ?

I'm in need of "saving" start point and end point, getting the total of hours between the start and end point (typicaly a workday or less) - i would need this data to be saved and handeled from an MySQL db.

Is the best thing to save timestamps, and work with them, or to save date in one field and start and end time in the other fields ?
TylerH4
Forum Newbie
Posts: 10
Joined: Sat May 26, 2012 8:45 pm

Re: working with hours / sum of hours

Post by TylerH4 »

I would do as you suggested, save the start and end timestams as their own field. When you need to find the total number of hours, you could simply do:

Code: Select all

$hours = ($endTime-$startTime)/60;
headbull
Forum Newbie
Posts: 10
Joined: Thu Jun 07, 2012 7:18 am

Re: working with hours / sum of hours

Post by headbull »

Any ideas how to solve the issue if the user sets startime to 21:00 and endtime 02:30 ? I really wont the user only to be able to choose one date.. Any ideas or solutions to how the system can spot/correct the date on the end time ?
Post Reply