Jump to content

Adding time intervals


php_novice2007

Recommended Posts

Hi,

 

If I have a mysql timestamp string, and I have another variable which stores a number in minutes, how can I add it to my string?

 

eg1. $current = 2007-02-26 12:32:06, $add = 6

So I want the result to be $res = 2007-02-26 12:38:06

 

eg2. $current = 2007-03-01 12:53:02, $add = 120

So result expected = 2007-03-01 14:53:02

 

eg3. $curent = 2007-03-05 23:15:24, $add = 150

Want result to be = 2007-03-06 01:45:24

 

Would I have to manually chop up the current string, add numbers to that, check for carry over either into the hour or to the next day? Is there an easier way?

 

Thanks~!

 

Link to comment
https://forums.phpfreaks.com/topic/43814-adding-time-intervals/
Share on other sites

Whats wrong with my code? :(

 

<?php
  date_default_timezone_set("Australia/NSW"); 
  echo "Today is " . date("Y-m-d H:i:s")."<br>";
  $makeup = date("Y-m-d H:i:s", mktime(14,38,13,2,7,2007));
  echo "Make up date is ". $makeup;
  echo "<br>";
  echo "Make up date + 150 minutes is";
  echo "<br>";
  $makeupNext = date("Y-m-d H:i:s", mktime(14,38,13,2,7,2007)) + (150*60);
  $makeupNextActual = date("Y-m-d H:i:s", $makeupNext);
  echo $makeupNextActual;
?>

 

The output I get is

 

Today is 2007-03-23 09:54:45

Make up date is 2007-02-07 14:38:13

Make up date + 150 minutes is

1970-01-01 13:03:27

 

I want $makeupNextActual = 2007-02-07 17:08:13, if I just print out $makeupNext I get 11007

 

I'm lost...

Link to comment
https://forums.phpfreaks.com/topic/43814-adding-time-intervals/#findComment-213110
Share on other sites

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.