Jump to content

choosing the current week


Poddy

Recommended Posts

Untested but should work -

 

SELECT your_columns FROM your_table WHERE
WEEK(your_date,mode) = WEEK(CURDATE(),mode) AND
YEAR(your_date) = YEAR(CURDATE())

 

Check the mysql manual for the "mode" value to use in the above query to match your definition of what a week is.

 

Edit: Here is an even shorter version (it pays to read a little further down in the manual) -

 

SELECT your_columns FROM your_table WHERE
YEARWEEK(your_date,mode) = YEARWEEK(CURDATE(),mode)

 

The "mode" value in YEARWEEK() is the same as you picked for the WEEK() function.

Untested but should work -

 

SELECT your_columns FROM your_table WHERE
WEEK(your_date,mode) = WEEK(CURDATE(),mode) AND
YEAR(your_date) = YEAR(CURDATE())

 

Check the mysql manual for the "mode" value to use in the above query to match your definition of what a week is.

 

Edit: Here is an even shorter version (it pays to read a little further down in the manual) -

 

SELECT your_columns FROM your_table WHERE
YEARWEEK(your_date,mode) = YEARWEEK(CURDATE(),mode)

 

The "mode" value in YEARWEEK() is the same as you picked for the WEEK() function.

 

thanks for the replys, but one thing i still do not understand, i need to select the CURRENT week so if i replace your_date with CURDATE it would just input the same result.. how will that work... what am i supposed to put in "your_date"

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.