i have this table and i cant change its format to yyyy-mm-dd because i have so many scripts that are related to this format dd-mm-yyyy , it would be a mess if iam gonna change its format
Id date 1 01-07-2014 2 02-07-2014 3 03-07-2014 4 05-07-2014 5 07-07-2014 6 14-07-2014 7 18-07-2014 8 19-07-2014 9 21-07-2014 10 01-08-2014 11 02-08-2014 12 03-08-2014
On the php file
$from = '01-07-2014';
$to = '02-08-2014';
i need to update some values from all the dates that are between 01-07-2014 and 01-09-2014 the format dd-mm-yyyy
iam using
UPDATE successlog
SET successlog.overtime ='00:00'
Where date >= '$from' AND
date <='$to'
its not working and am using the key between $from And $to also its not working
when the format was yyyy-mm-dd it was working normally but after i changed the format to dd-mm-yyyy its not working .
In PHP:
$from = date('Y-m-d', strtotime($from));
$to = date('Y-m-d', strtotime($to));
or in MySQL:
.. WHERE date BETWEEN STR_TO_DATE('$from','%d-%m-%Y') AND STR_TO_DATE('$to','%d-%m-%Y')
You need to change the format to yyyy-mm-dd in the sql only then it will work.
Try converting the $from and $to variable to yyyy-mm-dd format using PHP date function before adding the variable to sql string.
$from = '01-07-2014';
$from = date('Y-m-d',strtotime($from));
$to = '01-09-2014';
$to = date('Y-m-d',strtotime($to));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.