CodeDezk CodeDezk - 6 months ago 25
MySQL Question

sql query select date equal rows from datetime

I need to select the row when date equal particular date, where as the TIMESTAMP column contain datetime.

This works fine,

select USERNAME from ACCESSACTIVITY where UPPER(LOCATION)=UPPER('remote-PC')and TIMESTAMP = STR_TO_DATE('28-05-2016 01:00:00','%d-%m-%Y %H:%i:%s')


where as when I avoid time, it doesn't work.

select USERNAME from ACCESSACTIVITY where UPPER(LOCATION)=UPPER('remote-PC')and TIMESTAMP = STR_TO_DATE('28-05-2016 ','%d-%m-%Y')

Answer

You don't need the wildcards. Try this:

select USERNAME from ACCESSACTIVITY where UPPER(LOCATION)=UPPER('remote-PC')and DATE(TIMESTAMP) = STR_TO_DATE('28-05-2016 ','%d-%m-%Y')
Comments