add time for timestamp
Wha开发者_JS百科t is the best method for adding time to a timestamp? I have in a database
2011-10-09 10:29:23
and I would like add to this 20 days. How can I do that? I need an example for:
- 20 hours
- 20 days
You can use Date::add like this:
<?php
$date = new DateTime('2011-10-09 10:29:23');
$date->add(new DateInterval('P20D')); //use PT20H for 20 hours
echo $date->format('Y-m-d H:i:s');
?>
http://www.php.net/manual/en/function.strtotime.php
Use PHP's strtotime function like:
$newtimestamp = strtotime("+20 days", $yourtimestamp);
Another method that works well with Frame is
$time = date('Y-m-d H:i:s', time($foo->time_stamp + (24*60*60)));
where the number at the end is the old php method (*days*hours*mins*secs)
I recommend you to use unix_timestamps, with these you're able to work faster, and if the times were to be displayed to the user, you can use gmdate().
精彩评论