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