-1

Hello just a simple question here. Php's time related functions are confusing me ;-(

Given 2 variables

$start = "2013-07-25 20:24:13" ('Y-m-d H:i:s'); 
$duration = "0:55" ('H:i');

How may I add $duration to $start? should result in:

"2013-07-25 21:19:13"

meda
  • 45,103
  • 14
  • 92
  • 122
TNT_Larsn
  • 73
  • 8
  • http://php.net/manual/en/function.date-add.php – random_user_name Aug 22 '13 at 19:21
  • Things would probably be infinitely less confusing if you only used timestamps except for when you need to display the date. – Ariane Aug 22 '13 at 19:22
  • In addition to the dupe: http://stackoverflow.com/search?q=how+to+add+date+php – Gordon Aug 22 '13 at 19:38
  • That's wat I came up with: $start = strtotime($start); $duration = explode(':', $duration); $end = date("Y-m-d H:i:s", strtotime('+'.$duration[0].' hour '.$duration[1].' minutes', $start)); – TNT_Larsn Aug 23 '13 at 05:25

1 Answers1

2

Use DateTime() with DatePeriod()

$dt = new DateTime('2013-07-25 20:24:13');
$dt->add(new DatePeriod('P55M'));
echo $dt->format('Y-m-d H:i:s');
John Conde
  • 217,595
  • 99
  • 455
  • 496