Pedro Jimenez Pedro Jimenez - 1 month ago 6
MySQL Question

Problems white date and two variables

I have next code:

SELECT * FROM lc_t_ordenes
WHERE fecha_registro between date(%s) and date(%s)+.9
ORDER BY fecha_registro ASC


When the date is between
2016-10-01
and
2016-10-30
it works but when I try to find only records when date is
2016-10-31
doesn´t work.

In table date is
timestamp
. How can I find records between
date1 (2016-10-01 00:00:00)
and
date2 (2016-10-01 23:59:59)
?

User only puts
2016-10-01
.

Answer

How about this code:

SELECT *
FROM your_table
WHERE DATE(timestamp_column) = '2016-10-01';

Edit to your code:

SELECT * FROM lc_t_ordenes
WHERE DATE(fecha_registro) BETWEEN '2016-10-01' AND '2016-10-30'
ORDER BY fecha_registro ASC;

Reference: MySQL Date and Time Functions

Comments