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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.