Got a problem with time and posting into MySQL

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
boniggy
Forum Newbie
Posts: 3
Joined: Thu Sep 15, 2005 7:14 pm
Location: Mesa, AZ

Got a problem with time and posting into MySQL

Post by boniggy »

Current Versions:
PHP Version 5.0.4
MySQL 4.1.14
phpMyAdmin 2.6.3-pl1
Apache/2.0.54 (Win32)


Ok I have a project im working on for my work and even tho i've been around php for a number of years this is really taxing my idea's.

My main problem is that i have a form where people fill out their info. Two fields are Starttime and Endtime all in Military time (ie 13:00 and 15:00 hrs). My problem is that im tryin to get the total amount of hours between two different times, 13:00-15:00, correct format. All i get is 2 and that it.

This is what i have in the form assigntask.php file

Code: Select all

Start Time: (HH:MM)</td>
<td height="30" width="469" bgcolor="#EFF3F7" bordercolor="#FFFFFF">
<font face="Verdana"><input type=text name='starttime' size=5>*  (military time)</td></tr><tr><td height="30" width="55" bgcolor="#EFF3F7" bordercolor="#FFFFFF">
<img border="0" src="bc_new.gif" width="28" height="28"></td><td height="30" width="189" bgcolor="#EFF3F7" bordercolor="#FFFFFF">
<font face="Verdana" size="2">

End Time: (HH:MM)</td>
<td height="30" width="469" bgcolor="#EFF3F7" bordercolor="#FFFFFF">
<font face="Verdana"><input type=text name='endtime' size=5>*  (military time)</td></tr><tr><td height="30" width="55" bgcolor="#EFF3F7" bordercolor="#FFFFFF">
<img border="0" src="bc_new.gif" width="28" height="28"></td><td height="30" width="189" bgcolor="#EFF3F7" bordercolor="#FFFFFF">
<font face="Verdana" size="2">
After you hit submit it runs the file process.php which is where it pops it into the DB. I'm able to get it to add the 2 to the DB but again i need it in the right format. Also if i do a time with minutes in it (ie. 10:00 - 15:45) then it kicks out the 45mins and will only add the 5hrs.

If i use something like this in the process.php portion then i get a 5:00:02

Code: Select all

$hoursspent = date('h:i:s',$endtime - $starttime);
Please if anybody could help me out here i would greatly appreciate it.. I still have a little hair left.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Date and Time Functions wrote:SUBTIME(expr,expr2)

SUBTIME() subtracts expr2 from expr and returns the result. expr is a time or datetime expression, and expr2 is a time expression.

mysql> SELECT SUBTIME('1997-12-31 23:59:59.999999',
-> '1 1:1:1.000002');
-> '1997-12-30 22:58:58.999997'
mysql> SELECT SUBTIME('01:00:00.999999', '02:00:00.999998');
-> '-00:59:59.999999'
boniggy
Forum Newbie
Posts: 3
Joined: Thu Sep 15, 2005 7:14 pm
Location: Mesa, AZ

Post by boniggy »

Ok im completely drawing a blank on this. Doesnt this give me the command to run in the shell? I thought i needed a command to run it in the .php file.
ryanlwh
Forum Commoner
Posts: 84
Joined: Wed Sep 14, 2005 1:29 pm

Post by ryanlwh »

then just modify what fyed gave you into a php string... and SUBTIME is a sql command.. so yerr

Code: Select all

$query  = mysql_query("SELECT SUBTIME(blah blah blah)");
Post Reply