bschultz Posted January 24, 2008 Share Posted January 24, 2008 I'm trying to insert time into a database. The problem that I'm running into is that I need to subtract the time inserted by 20 minutes first. So, 9:15 (nine minutes, 15 seconds) would have to read 11:45 (20 minutes minus 9:15). I can get the time conversion done with this: $myminutes = $_POST[minutes]; $myseconds = $_POST[seconds]; $convertedmins = $myminutes * 60; $totaltime = (1200 - ($convertedmins + $myseconds)); if ($totaltime > 0) { $mins = floor ($totaltime / 60); $secs = $totaltime % 60; printf ("%d:%02.0f", $mins, $secs); } but how do I insert the printf into the database? I've tried making the printf statement a variable, and inserting the variable, but I got a syntax error. Thanks. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 24, 2008 Share Posted January 24, 2008 <SHUDDER> Use "- INTERVAL 20 MINUTE"... don't use PHP for date math. </SHUDDER> Quote Link to comment Share on other sites More sharing options...
bschultz Posted January 24, 2008 Author Share Posted January 24, 2008 I wanted the information to be inserted as text, and not in TIME format. That's why I converted to seconds, and then did my math. I also didn't know how to make 20:00 be minutes and seconds, and not hours and minutes...that's another reason why I did it the way I did. Like I said before, the value that is "printf 'd" is correct...but I can't get it into the database that way. What's a better way? Quote Link to comment Share on other sites More sharing options...
fenway Posted January 24, 2008 Share Posted January 24, 2008 Text? Noooo.... How about 00:20:00? Quote Link to comment Share on other sites More sharing options...
bschultz Posted January 25, 2008 Author Share Posted January 25, 2008 Still doesn't work...unexpected T_VARIABLE on this line $hockeytime = "INTERVAL 20 MINUTE - $_POST[time]"; Here's the whole code: <form name="form1" method="post" action="timecheck.php"> <label> <input type="text" name="time" id="time"> </label> enter the time on the scoreboard here </form> <?php time_format(time, '%i-%s') $hockeytime = "INTERVAL 20 MINUTE - $_POST[time]"; echo $hockeytime; ?> Quote Link to comment Share on other sites More sharing options...
fenway Posted January 26, 2008 Share Posted January 26, 2008 Format the time correct, then use str_to_date() to make it a true mysql TIME field, and only then case you do date math on it. Quote Link to comment 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.