themasmul themasmul - 4 months ago 15
MySQL Question

Mysql Add DATE_COLUMN 3 DAYS with querry

i've ben asking many question here, but it was dead end, i just wanna make simple select from date_column+3 day, im new to this mysql,

i'ce tried with this query

SELECT * from pemesanan where pemesanan.`date` = DATE(DATE_ADD(date, INTERVAL 3 DAY))


but the result is empty, here's my column

date
2016-08-10
2016-08-04
2016-08-07


it must be show the 2016-08-10 data, but its not,

can somebody enlighten me, i've frustated with this

Answer

If you use date right side you should use date left side

  SELECT * 
  from pemesanan 
  where  date(pemesanan.`date`) = DATE(DATE_ADD(NOW(), INTERVAL 3 DAY))

If you use the same date pemesanan.date you never get pemesanan.date = pemesanan.date +3

but if you want select the date older than 3 day you shuold use

  SELECT * 
  from pemesanan 
  where  date(pemesanan.`date`) <= DATE(DATE_sub(NOW(), INTERVAL 3 DAY))

and for delete

  DELETE from pemesanan 
  where  date(pemesanan.`date`) <= DATE(DATE_sub(NOW(), INTERVAL 3 DAY))

in your case

  SELECT * 
  from pemesanan 
  where  date(pemesanan.tanggal)  <= DATE(DATE_sub(NOW(), INTERVAL 3 DAY))