Page 1 of 1

can't get week of year from date in dd-mm-yyyy format

Posted: Mon May 26, 2008 10:56 am
by Porsche.V
hi,

i need to list the production of a factory for a certain week, for this the user enters a date, and, from this date, i have to know the production for the week in which that day is.. for instance day 5 is a tuesday, so after the user entered 05-02-2008, i have to find out what day is sunday (before) and saturday (after) so i can list in a sql query between.

i thought to first get to know the week number by using: $week=date('W',strtotime($day));

but this day is passed as dd-mm-yyyy, and php only is accepting yyyy-mm-dd, or it returns nonsense weeks.

can i put it the way i want? how?

this is my problem but, if you already did something like this do you have any suggestion for the "whole" problem?

thanks

Re: can't get week of year from date in dd-mm-yyyy format

Posted: Mon May 26, 2008 11:03 am
by Ambush Commander
strtotime only accepts specific formats, so if it doesn't support dd-mm-yyyy you'll have to parse it yourself. The easiest way would be to rewrite it into a form strtotime does support, like:

Code: Select all

 
list($d, $m, $y) = explode('-', $date);
$week=date('W',strtotime("$y-$m-$d"));