how to display weeks

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
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

how to display weeks

Post 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. :)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Select it that way in your query then just display it in PHP.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post 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.:)
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post 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
Post Reply