Ad Code

MySQL results todat, yesterday, last week, last month and last year

my datefield (artists.onlineDate) is yyy-mm-dd


-- Today
SELECT * FROM artists WHERE DATE(artists.onlineDate) = CURDATE()

-- Yesterday
SELECT * FROM artists WHERE DATE(artists.onlineDate) = DATE(CURDATE())-1

-- Current Week
SELECT * FROM artists WHERE WEEK(artists.onlineDate, 3) = WEEK(CURDATE(), 3)

-- Last Week
SELECT * FROM artists WHERE WEEK(artists.onlineDate, 3) = WEEK(CURDATE(), 3)-1

-- Current Month
SELECT * FROM artists WHERE MONTH(artists.onlineDate) = MONTH(CURDATE())

-- Last Month
SELECT * FROM artists WHERE MONTH(artists.onlineDate) = MONTH(CURDATE())-1

-- Current Year
SELECT * FROM artists WHERE YEAR(artists.onlineDate) = YEAR(CURDATE())

-- Last Year
SELECT * FROM artists WHERE YEAR(artists.onlineDate) = YEAR(CURDATE())-1

Post a Comment

0 Comments