Ver Mensaje Individual
  #2 (permalink)  
Antiguo 18/10/2013, 22:55
Avatar de bNd170
bNd170
 
Fecha de Ingreso: agosto-2009
Ubicación: $this->setLocation('Valencia', 'Spain');
Mensajes: 365
Antigüedad: 15 años, 5 meses
Puntos: 13
Respuesta: calcular fechas en php

Te recomiendo trabajar con fechas UNIX para hacer cálculos.

Las fechas UNIX van en segundos, por lo que es muy sencillo sumar minutos, horas, dias e incluso semanas, meses y años.

Para tu problema es bastante sencilla la solucion, tan solo debes coger la fecha inicial que te de el usuario y la fecha de ahora.

Las restas y calculas cuantas semanas hay en ese periodo de tiempo.

Este tipo de funciones son muy comunes y sencillas de encontrar en internet.

Aqui te dejo un par que acabo de encontrar.

Código PHP:
Ver original
  1. function days_between($datefrom,$dateto){
  2.     $fromday_start = mktime(0,0,0,date("m",$datefrom),date("d",$datefrom),date("Y",$datefrom));
  3.     $diff = $dateto - $datefrom;
  4.     $days = intval( $diff / 86400 ); // 86400  / day
  5.  
  6.     if( ($datefrom - $fromday_start) + ($diff % 86400) > 86400 )
  7.         $days++;
  8.  
  9.     return  $days;
  10. }
  11.  
  12. function weeks_between($datefrom, $dateto)
  13. {
  14.     $day_of_week = date("w", $datefrom);
  15.     $fromweek_start = $datefrom - ($day_of_week * 86400) - ($datefrom % 86400);
  16.     $diff_days = days_between($datefrom, $dateto);
  17.     $diff_weeks = intval($diff_days / 7);
  18.     $seconds_left = ($diff_days % 7) * 86400;
  19.  
  20.     if( ($datefrom - $fromweek_start) + $seconds_left > 604800 )
  21.         $diff_weeks ++;
  22.  
  23.     return $diff_weeks;
  24. }