Jump to content

Adding seconds to a timestamp


LLeoun

Recommended Posts

Hi all,

 

I'm doing some maths with the date:

 

I want to add 9000 seconds to the date 2010-02-13T06:00:00+01:00

So I do a mktime timestamp with the date and I add the 9000 seconds (it's all seconds, isn't it?)

But when I turn the addition's result back into date format, the 9000 seconds (2 hours and a half) are wrongly added.

 

What am I doing wrong??

 

Thanks a lot!

 

<?php
  $beginTime= "2010-02-13T06:00:00+01:00";
  $duration= 9000;

$r = substr($beginTime, 0, 19);
$year= substr($r,0,4);
$month = substr($r,5,2);
$day = substr($r,8,2);
$hour= substr($r,11,2);
$minute = substr($r,14,2);
$second = substr($r,17,2);

echo"<br>";
echo $beginTime; echo" is the date in the beginning, and this is the duration: ";echo $duration;
echo"<br>";
$beginTimeStamp = mktime($hour, $minute, $second, $month, $day, $year);
$endTimeStamp = $beginTimeStamp + $duration; 
echo $beginTimeStamp;echo" + duration = ";echo $endTimeStamp;echo" which is the date: ";echo date("Ymd-h:m:s",$endTimeStamp);

?>

Link to comment
https://forums.phpfreaks.com/topic/193371-adding-seconds-to-a-timestamp/
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.