0

I have a date and timestamp in HL7 format : 201402181659

That represents 2014 02 18 at 16:59

it's offset by +11:00 hours so I need to be able to add 11 hours to the date/time. Any ideas?

John Conde
  • 217,595
  • 99
  • 455
  • 496
Legless
  • 55
  • 3
  • Convert it to a date object and then add the desired amount of hours, then convert it back to the format you like. – Tobias Feb 25 '14 at 03:12
  • See [`this answer`](http://stackoverflow.com/a/21998936/) and change it to `11` also consult http://www.php.net/manual/en/datetime.add.php – Funk Forty Niner Feb 25 '14 at 03:12

1 Answers1

4

You can use DateTime::createFromFormat() to parse the string and then DateTime::modify() to add 11 hours to it:

$date = DateTime::createFromFormat('YmdHis', '201402181659');
$date->modify('+11 hours');
echo $date->format('YmdHis');

You can also use DateTime::add() with DateInterval() to add the 11 hours:

$date = DateTime::createFromFormat('YmdHis', '201402181659');
$date->add(new DateInterval('PT11H'));
echo $date->format('YmdHis');
John Conde
  • 217,595
  • 99
  • 455
  • 496