Jump to content

convert before insert into db


bschultz

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/87568-convert-before-insert-into-db/
Share on other sites

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?

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;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.