¿Es posible obtener la primera/última fecha de una semana usando PHP Relative Date Time format?Obteniendo la primera/última fecha de la semana
He tratado de hacer:
date_default_timezone_set('Europe/Amsterdam');
$date = new DateTime();
$date->modify('first day of this week'); // to get the current week's first date
echo $date->format('Y-m-d'); // outputs 2011-12-19
$date->modify('first day of week 50'); // to get the first date of any week by weeknumber
echo $date->format('Y-m-d'); // outputs 2011-12-18
$date->modify('last day of this week'); // to get the current week's last date
echo $date->format('Y-m-d'); // outputs 2011-12-17
$date->modify('last day of week 50'); // to get the last date of any week by weeknumber
echo $date->format('Y-m-d'); // outputs 2011-12-18
Como se puede see que no emitirá las fechas correctas.
De acuerdo con the docs esto debería ser posible si estoy en lo correcto.
¿Estoy haciendo algo terrible mal?
EDITAR
necesito utilizar DateTime de PHP para las fechas en el futuro lejano.
ACTUALIZACIÓN
Se pone único extraño ahora. He hecho algunas pruebas más.
de Windows PHP 5.3.3
2011-12-01
Warning: DateTime::modify() [datetime.modify]: Failed to parse time string (first day of week 50) at position 13 (w): The timezone could not be found in the database in C:\Users\Gerrie\Desktop\ph\Websites\Charts\www.charts.com\public\index.php on line 9
2011-12-01
2011-11-30
Warning: DateTime::modify() [datetime.modify]: Failed to parse time string (last day of week 50) at position 12 (w): The timezone could not be found in the database in C:\Users\Gerrie\Desktop\ph\Websites\Charts\www.charts.com\public\index.php on line 15
2011-11-30
Linux 5.3.8
2011-12-01
2011-12-01
2011-11-30
2011-11-30
¿Esto no depende de la localidad, si el domingo o el lunes es el primer día de la semana? – mario
@mario: No sé si me lo dices. De cualquier forma, los dos primeros deberían emitir lo mismo. Lo mismo ocurre con los dos últimos en mi humilde opinión. Si comienza el domingo/lunes – PeeHaa