0

I have an input where you can select a time between 00:00 - 24:00 (displayed in "utleid" and 2 radio buttons where you can choose 30 minutes or 60 minutes.

I want the input where you can write your own time and + it with either 30 or 60 minutes depending on what they choose

so lets for example say i choose "30" and type in 12:00 i want it to insert into the "inntid" "12:30".

I tried doing something but it didnt work :P

DATABASE: DATABASE

HTML:

<div class="tid">
<label class="container"><span class="tidtekst">30m</span>
  <input type="radio" class="checked" name="tid" id="tid" value="30">
  <span class="checkmark"></span>
</label>
<label class="container"><span class="tidtekst">60m</span>
  <input type="radio" name="tid" value="60">
  <span class="checkmark"></span>
</label>
<input type="text" name="tid_custom" id="egentid" placeholder="Tid">
</div>


<h2 class="overskrift">Tiden klokka starter:</h2>
  <input type="time" id="utleidnar" name="utleidnar"
       min="00:00" max="24:00" required>

PHP:

$velgut = "SELECT utleid FROM utleie";
$velgtid = "SELECT tid FROM utleie";
$inntid = "INSERT INTO utleie (inntid) VALUES ('$velgut + $velginn')";

if (@$_POST["submit"] != "") {
    $baatnr = @$_POST["baatnr"];
    $fornavn = @$_POST["fornavn"];
    $etternavn = @$_POST["etternavn"];
    $tid = @$_POST["tid"];

    if ($tid == null) {
        $tid = @$_POST["tid_custom"];
    }

    $kr = @$_POST["kr"];

    if ($kr == null) {
        $kr = @$_POST["kr_custom"];
    }

    $utleidnar = @$_POST["utleidnar"];
}

$sql = "INSERT INTO utleie (utleid, inntid, baatnr, fornavn, etternavn, tid, kr)
VALUES ('$utleidnar', '', '$baatnr', '$fornavn', '$etternavn', '$tid', '$kr')";

3 Answers3

1

I think you need to parse the value in php. Try something like this:

$timestamp = strtotime('12:00') + 30*60;
$time = date('H:i', $timestamp);
treyBake
  • 6,440
  • 6
  • 26
  • 57
b0r1s
  • 111
  • 4
1

Use the PHP builtin datetime function to calculate the additional 30 or 60 minutes.

$utleidnar = '13:00';
$tid = 60;

$stime = DateTime::createFromFormat('H:i',$utleidnar);
$stime->add(new DateInterval('PT' . $tid . 'M'));
$inntid = $stime->format('H:i');
echo $inntid;  // this has the new value you want

Results in:

14:00

Dave
  • 5,108
  • 16
  • 30
  • 40
0

can't you use mtkime?

$explodedTime = explode(':',$utleidnar);
$tid = abs($_POST['tid']);
$time = date('H:i', mktime($explodedTime[0],$explodedTime[1] + $tid,0));
imposterSyndrome
  • 896
  • 1
  • 7
  • 18