ferrarisp

datas_somaDiasMesesAnos.php

Aug 20th, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. # site referencia : http://www.rafaeltheodoro.com.br/php/funcoes-para-somar-dias-meses-ou-anos-em-datas/
  2.  
  3. # função fazer a soma na data atual do servidor
  4.     strftime('%d/%m/%Y', strtotime('+3 days'));
  5.     strftime('%d/%m/%Y', strtotime('+3 months'));
  6.     strftime('%d/%m/%Y', strtotime('+3 years'));
  7.  
  8. # função quando sua data é um Date, Date Time ou um Timestamp vindo de um banco de dados
  9.     function makeDateTime($date, $days=0, $mounths=0, $years=0)
  10.     {
  11.         $date = date('d/m/Y', strtotime($date));
  12.         $date = explode("/", $date);
  13.         return date('d/m/Y', mktime(0, 0, 0, $date[1] + $mounths, $date[0] +  $days, $date[2] + $years) );
  14.     }
  15.  
  16. # utilizando a função abaixo Se sua data é uma STRING:
  17.     function makeDateString($date, $days=0, $mounths=0, $years=0)
  18.     {
  19.         $date = explode("/", $date);
  20.         return date('d/m/Y', mktime(0, 0, 0, $date[1] + $mounths, $date[0] +  $days, $date[2] + $years) );
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment