Seleccionar consulta mysql entre fecha?
¿Cómo seleccionar datos de la tabla mysql desde la fecha pasada hasta la fecha actual? Por ejemplo, Seleccione datos desde el 1 de enero de 2009 hasta la fecha actual ??
Mi columna "datetime" está en el tipo de fecha datetime. Por favor ayuda, gracias
Editar:
Si digamos que quiero obtener datos del día por día a partir del 1 de enero de 2009, ¿cómo escribir la consulta? Utilice la cuenta y entre la función?
40
3 answers
select * from *table_name* where *datetime_column* between '01/01/2009' and curdate()
O usando >=
y <=
:
select * from *table_name* where *datetime_column* >= '01/01/2009' and *datetime_column* <= curdate()
66
Author: Noah Heldman,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-03-05 11:48:43
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-03-05 11:48:43
Todo lo anterior funciona, y aquí hay otra manera si solo desea un número de días/tiempo atrás en lugar de una fecha de entrada
select * from *table_name* where *datetime_column* BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY) AND NOW()
20
Author: shakirthow,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-10-24 02:59:43
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-10-24 02:59:43
Puedes usar now()
como:
Select data from tablename where datetime >= "01-01-2009 00:00:00" and datetime <= now();
12
Author: Kerri,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-08-02 17:11:42
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-08-02 17:11:42