perficut Posted November 24, 2008 Share Posted November 24, 2008 Can you define the value of a field to automaticaly perform a math function between two other fields? I have the following fields in my table, OnSiteTime, OffSiteTime, and TotalTime. Can I define TotalTime to automatically subtract OnSiteTime from OffSiteTime in the field definition somewhere? Quote Link to comment https://forums.phpfreaks.com/topic/134041-math-functions-inside-mysql/ Share on other sites More sharing options...
revraz Posted November 24, 2008 Share Posted November 24, 2008 Give it a try. Quote Link to comment https://forums.phpfreaks.com/topic/134041-math-functions-inside-mysql/#findComment-697737 Share on other sites More sharing options...
perficut Posted November 24, 2008 Author Share Posted November 24, 2008 I tried, but get an error. Not sure If I am using correct syntex ord not Quote Link to comment https://forums.phpfreaks.com/topic/134041-math-functions-inside-mysql/#findComment-697746 Share on other sites More sharing options...
revraz Posted November 24, 2008 Share Posted November 24, 2008 Post the code and the error. Quote Link to comment https://forums.phpfreaks.com/topic/134041-math-functions-inside-mysql/#findComment-697761 Share on other sites More sharing options...
perficut Posted November 24, 2008 Author Share Posted November 24, 2008 Apparently YOU CAN NOT do this. According to the phpadmin help section. So perhaps someone can help me with the code then. As you can see, I want to calculate the amount of time on each jobsite, based on the arrival and departure times. But I am having a bit of a problem with the time formatting. A lot of the work will be done during the eveing, so I will need to be able to figure the time spend at a job when the clock switches from 11:59 pm to 12:00 am. Example: 11:00 pm - 11:30 pm = 30min TotalTime but.... 11:45 pm - 12:15 am = screwed up number. how can I do this with php? Quote Link to comment https://forums.phpfreaks.com/topic/134041-math-functions-inside-mysql/#findComment-698034 Share on other sites More sharing options...
revraz Posted November 24, 2008 Share Posted November 24, 2008 Use UNIX time stamps. Quote Link to comment https://forums.phpfreaks.com/topic/134041-math-functions-inside-mysql/#findComment-698045 Share on other sites More sharing options...
perficut Posted November 24, 2008 Author Share Posted November 24, 2008 Heres a small code I ran across that sort of works. Two problems. One is I would like to use the 24hr military time settings if possible, since that is how my original form asks for it. If not, thats fine, ill change the form. Second problem is, getting this code to realize the transformation from 11 at night to 2 the next morning. It thinks there is 9hour of difference. Any suggestions? <? $start_time = $_REQUEST['start_time']; $end_time = $_REQUEST['end_time']; $action = $_REQUEST['action']; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <body> <h3>Parse Times</h3> <form action="<?= $_SERVER['PHP_SELF'] ?>"> Enter the start time (hours:minutes) <input type="text" name="start_time" value="<?= $start_time ?>" size="60"> <br/> Enter the end time (hours:minutes) <input type="text" name="end_time" value="<?= $end_time ?>" size="60"> <br/> <input type="submit" value="Go!"> <br/> <input type="hidden" name="action" value="go"> </form> <hr> <? if($action && ($action == "go")){ list($hours, $minutes) = split(':', $start_time); $startTimestamp = mktime($hours, $minutes); list($hours, $minutes) = split(':', $end_time); $endTimestamp = mktime($hours, $minutes); $seconds = $endTimestamp - $startTimestamp; $minutes = ($seconds / 60) % 60; $hours = round($seconds / (60 * 60)); echo "Time On Job Site: <b>$hours</b> hours and <b>$minutes</b> minutes"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/134041-math-functions-inside-mysql/#findComment-698081 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.