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/08f4ff22b38037b5eac8c85c91c933c6 to your computer and use it in GitHub Desktop.

Select an option

Save YurePereira/08f4ff22b38037b5eac8c85c91c933c6 to your computer and use it in GitHub Desktop.
Usando Relative Formats para definir o período do DateInterval para alterar nossas datas
<?php
$dateTime = new DateTime('2016-12-01 00:00:01');
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
//P1YT10H55S
$dateTime->add(DateInterval::createFromDateString('1 year + 10 hours + 55 seconds'));
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
//PT5H30M20S
$dateTime->sub(DateInterval::createFromDateString('5 hours + 30 minutes + 20 seconds'));
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
//P1Y4M10DT2H30M50S
$dateTime->add(DateInterval::createFromDateString('1 year + 4 months + 10 days + 2 hours + 30 minutes + 50 seconds'));
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