Recently, I faced a problem when the date was saved in different fields month, year and date. I need to club all these fields together and run a between query on it.
Another issue which was there was that Date has '0' contacted if the value is less than 10 and if new date created do not follow this pattern the result does not come out correct. So, I used LPAD of MYSQL which fills zero correspondingly.
SQL QUERY :-
SELECT stamp, COUNT(*) AS cnt FROM diary WHERE (CONCAT (CONCAT_WS( '-', yearstart, LPAD( monthstart, 2, '0' ) + 1 , LPAD( datestart, 2, '0' ) ) , ' 00:00:00') BETWEEN '{$data['start_date']} 00:00:00' AND '{$data['end_date']} 23:59:59' ) and userid = {$data['userid']} and status = 1 GROUP BY stamp ";
0 Comment(s)