How do I get data from mysql based on week number?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Blade
Forum Newbie
Posts: 6
Joined: Mon May 27, 2002 7:14 am

How do I get data from mysql based on week number?

Post by Blade »

I want to extract data from a mysql table based on week numbers.

something like this: select * from table where (date = week 42)

I know how to do it in php, but I there is no need to load the whole database into memory, when I know it can be done with a simple sql statement. I just dont know how, so can some kind person please show me how?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

http://www.mysql.com/doc/en/Date_and_ti ... tions.html

Maybe something like:

Code: Select all

SELECT field1, field2, field3, date FROM table WHERE WEEK(date) = 42
Mac
Blade
Forum Newbie
Posts: 6
Joined: Mon May 27, 2002 7:14 am

Post by Blade »

Thats it :)

Thanks a lot. I did look at the mysql page before, but I didnt really understand how to use the info until now.
Post Reply