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

Select an option

Save YurePereira/6c03e2584be199d4d17c2af502c08c86 to your computer and use it in GitHub Desktop.
Modificando datas com o métodos modify da classe DateTime
<?php
$dateTime = new DateTime('2016-12-01 00:00:01');
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
//Adiciondo dez dias a nossa data
$dateTime->modify('10 days');
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
//Subtraindo dez dias de nossa data
$dateTime->modify('-10 days');
echo $dateTime->format('d/m/Y H:i:s'), PHP_EOL;
//Adicionado 1 anos, 4 meses e 25 dias a nossa data
$dateTime->modify('1 year +4 months +25 days');
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