Estoy atascado con un problema en MySQL. Quiero obtener el recuento de registros entre dos entradas de fecha y hora.
Por ejemplo:
Tengo una columna en mi tabla llamada ‘creada’ que tiene el tipo de datos de datetime
.
Quiero contar los registros que se crearon con fecha y hora entre “TODAY’S 4:30 AM” y “CURRENT DATE TIME”.
Probé algunas de las funciones de MySQL pero todavía no tuve suerte.
¿Puedes ayudarme con esto? Gracias.
Puede estar con:
SELECT count(*) FROM `table` where created_at>='2011-03-17 06:42:10' and created_at<='2011-03-17 07:42:50';
o usar between
:
SELECT count(*) FROM `table` where created_at between '2011-03-17 06:42:10' and '2011-03-17 07:42:50';
Puede cambiar la fecha y hora según su necesidad. Puede ser use curdate()
o now()
para obtener las fechas deseadas.
select * from yourtable where created < now() and created > '2011-04-25 04:00:00'
select * from yourtable where created < now() and created > concat(curdate(),' 4:30:00 AM')