PDA

Click to See Complete Forum and Search --> : Dates and Weeks


AvisSoft
May 5th, 2005, 03:03 PM
Hello,

We know that there are 52-53 weeks in an year. Now what i want to achieve is that how do i determine which date falls in which week ?

I have numbered weeks from 1 to 52. So i the date is like 1-1-2005 then it should tell me that its in "Week 1" and if date is: 8-1-2005 then it should say its in "Week 2" and so on.

Please tell me how can i do this ?

Thanks.

visualAd
May 6th, 2005, 08:53 AM
You can use the url() (http://uk2.php.net/date) date function.

$week_number = (int) date('W', $date);

AvisSoft
May 6th, 2005, 09:17 AM
Hi

it does not seems to be working. I am getting 1 as weeknumber no matter what date i put in. I am using format dd-mm-yyyy.

$date = "13-05-2005";
$week_number = (int) date('W', $date);
print $week_number;

Please help

Thanks

visualAd
May 6th, 2005, 09:20 AM
You need to first convert that string to a timestamp. Does the date come from a MySql database?

AvisSoft
May 6th, 2005, 10:24 AM
Hi,

yes it wil come from mysql db.

Thanks

visualAd
May 7th, 2005, 05:57 PM
Again, in MySql you can use a function which does this in the SQL query:

SELECT DATE_FORMAT(date, '%U');

The DATE_FORMAT() function is documented fully here (http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html).