Skip to content

Instantly share code, notes, and snippets.

@YurePereira
Last active June 19, 2019 14:52
Show Gist options
  • Select an option

  • Save YurePereira/d0faba6bacd3e175b4e77fa9ed4cfcee to your computer and use it in GitHub Desktop.

Select an option

Save YurePereira/d0faba6bacd3e175b4e77fa9ed4cfcee to your computer and use it in GitHub Desktop.
Usando Period Designators com DateInterval para alterar datas
<?php
$dateTime = new DateTime('2016-12-01 00:00:01');
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
$dateTime->add(new DateInterval('P1YT10H55S'));
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
$dateTime->sub(new DateInterval('PT5H30M20S'));
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
$dateTime->add(new DateInterval('P1Y4M10DT2H30M50S'));
echo $dateTime->format('d/m/Y H:i:s');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment