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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Porsche.V
Forum Newbie
Posts: 3
Joined: Mon May 26, 2008 10:49 am

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

Post 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
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

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

Post 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"));
 
Post Reply