Nisarg Nisarg - 2 months ago 6x
SQL Question

match date in mysql and give result

I have written query in mysql as

select * from tblstafftasks as tst join tblstafftaskassignees as tsta on tsta.taskid = join tblstaff as ts on ts.staffid = tsta.staffid where tst.startdate like '2016-07-21' or '2016-07-21' between tst.startdate and tst.duedate and tst.rel_id = 1

My database looks like :

enter image description here

When I have written above query it runs perfect but does not give any result.

Here I have used 2016-07-21 that match with the startdate so it not give any result. So what query should I have to write to get result if it match with the startdate.?

Here i pass date in simple Y-m-d format and in database it store as datetime so help me to solve this query.


It seems like you want to compare a date with DATETIME data types. If you want to compare just with the date of the DATETIME field, do something like this:

SELECT * FROM tblstafftasks AS tst
JOIN tblstafftaskassignees AS tsta ON tsta.taskid =
JOIN tblstaff AS ts ON ts.staffid = tsta.staffid
WHERE DATE(tst.startdate) <= '2016-07-21'
AND DATE(tst.duedate) >= '2016-07-21'