Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Where clause with specific date format?

Tags:

php

mysql

My table have data structure like this

    cate_id  task_id   date_start              date_end                other
         34     14   2012-06-27 10:21:39    2012-06-27 10:21:42     Volume
         34     14   2012-06-27 10:21:42    2016-01-01 00:00:00     Volume




UPDATE tbl SET other ='new'
WHERE task_id =14 
AND cate_id=34
AND DATE_FORMAT('date_start','%Y-%m-%d')='2012-06-27' 
AND DATE_FORMAT('date_end','%Y-%m-%d')='2016-01-01';

My goal is only compare the date with format '%Y-%m-%d' not whole the value.

Can do like the above mysql Script? Because it succeed executed sql script ,but does not update the col that I have specific? Anyone could tell me please? thanks

like image 890
sophie Avatar asked Dec 11 '25 13:12

sophie


1 Answers

Hum...

Try removing the quotes around date_start and date_end:

AND DATE_FORMAT(date_start,'%Y-%m-%d')='2012-06-27' 
AND DATE_FORMAT(date_end,'%Y-%m-%d')='2016-01-01';
like image 87
Olivier Coilland Avatar answered Dec 13 '25 02:12

Olivier Coilland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!