Blog

SELECT IN MYSQL CURRENT DAY, CURRENT WEEK, LAST WEEK

  • 06.07.2016
  • scion

Selecting records for the current day:

SELECT *
FROM (`table`)
WHERE date = CURDATE()  

 

Selecting records for the current week:

SELECT SUM(o_price) price
FROM (`orders`)
WHERE YEARWEEK(`o_date`) = YEARWEEK(CURDATE()) 
 

Selecting records for the last week:

SELECT *
FROM (
`table`
)
WHERE YEARWEEK( `date` ) = YEARWEEK( CURDATE( ) + INTERVAL 1 WEEK )
LIMIT 0 , 30