Page 1 of 1
how to display weeks
Posted: Thu May 10, 2007 7:35 pm
by pleigh
hi, i have this query
Code: Select all
$query = "SELECT distinct date_format(l.date, '%V') as week_number, date_format(l.date, '%X%V') as fixed_week_number ".
"FROM Logs l ".
"ORDER BY date_format(l.date, '%X %V')";
i want to display in <select> the fixed_week_number in words like for example may13 - may19. how can i achieve this in php??
thanks in advance.

Posted: Thu May 10, 2007 7:55 pm
by RobertGonzalez
Select it that way in your query then just display it in PHP.
Posted: Thu May 10, 2007 8:02 pm
by pleigh
hi, thanks for the reply, i tried that but it returned the year and the week number (200618) something like that....what i want to achieve is that i will be able to reflect the value of that date in my php page, and its range like may6 - may12.
Posted: Fri May 11, 2007 11:24 am
by RobertGonzalez
You can use the MySQL CONCAT() function to concatenate a string using parts, or you can select the data, then in PHP code use the
strtotime() function in conjunction with the
date() function to piece together what you are looking to do.
Do you have any code that you can show as to what you have done already? Even pseudo would be helpful.
Posted: Mon May 14, 2007 8:26 pm
by pleigh
hi, thanks for the reply...ok, just to make it simple, if i have the week 1 of 2007 (which is january 7 because sunday is my start of the week).. i want to display that as january 7 - january 13 as the first week, and so on...how can i achieve that? again, i was able to retrieve the number of week in mysql, but i don't know how to get its range. thanks again.

Posted: Tue May 15, 2007 4:14 am
by stereofrog
Try selecting dates of next/last sunday instead of week numbers:
Code: Select all
SELECT ...
from_days(to_days(DAT) - date_format(DAT, '%w') + 0) as last_sunday,
from_days(to_days(DAT) - date_format(DAT, '%w') + 7) as next_sunday