Jump to content

[SOLVED] Adding minutes to 24hour


PHPTOM

Recommended Posts

Hi,

I am coding a timetable and basically I want to know how to add minutes to 24hour.

I have for example 13:00 in the database, and I want to add 120 minutes to this. Can someone assist me in a function to do this please?

 

Thanks

Link to comment
Share on other sites

Sorry doesnt work, it displays 7212.

 

Basically

I have:

A while, getting the start time from mysql. 
$starttime = $a['time'];
Then I put this
$newtime = strtotime("+2 hours",$starttime);
and
echo $newtime;

 

It displays:

7212
Link to comment
Share on other sites

You have to echo it out using [m]date/m]

 

<?php
$newtime = strtotime("+2 hours",$a['time']);
echo date('H:i', $newtime);
?>

 

Should print it out right.

 

Just remember, we usually provide examples, it is up to you to take those examples and implement them correctly in your code, IE replacing "$oldtime" to be $a['time'].

Link to comment
Share on other sites

Yup, I know about examples. I added that variable to show you better, as you won't know what $a['time'] means. I'm having problems with it not working the correct hour out.

 

<table width="100%" cellpadding="4" cellspacing="0" border="0">
<tr>
<td><font class="heading2">Start</font></td>
<td><font class="heading2">End</font></td>
<td><font class="heading2">Presenter</font></td>
</tr>
<?PHP
$q = mysql_query("SELECT * FROM `timetable` WHERE `day` = '".$_GET['day']."' ORDER BY `time` ASC");
while($a = mysql_fetch_array($q)){
$newtime = strtotime("+2 hours", $a['time']);
?>
    <tr>
    <td><?=$a['time'];?></td>
    <td><?=date('H:i', $newtime);?></td>
    <td><?=$a[presenter];?></td>
    </tr>
<?PHP } ?>
</table>

 

This is what I have dispayed:

17:00  02:00  Tom

 

 

Any ideas? The 02:00 should show 19:00.

Link to comment
Share on other sites

Not sure why, I just ran the test on my server doing this:

 

<?php
$a['time'] = "17:00";
$newtime = date("H:i", strtotime($a['time'])+3600*2); // 3600*2 = 2 hours
echo "The time should be 19:00 and (drum role) the time is: " . $newtime;
die();
?>

 

Output:

The time should be 19:00 and (drum role) the time is: 19:00

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.