-
Dates and Weeks
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.
-
Re: Dates and Weeks
You can use the url() date function.
PHP Code:
$week_number = (int) date('W', $date);
-
Re: Dates and Weeks
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
-
Re: Dates and Weeks
You need to first convert that string to a timestamp. Does the date come from a MySql database?
-
Re: Dates and Weeks
Hi,
yes it wil come from mysql db.
Thanks
-
Re: Dates and Weeks
Again, in MySql you can use a function which does this in the SQL query:
Code:
SELECT DATE_FORMAT(date, '%U');
The DATE_FORMAT() function is documented fully here.