I have a quick question. I'm have a db an audit Table with a datetime column in it. (i.e 2012-03-27 00:00:00) and I'm building a mySQL query to return a set of rows if the date is in between the two dates I'm giving it.
so far my query looks like this:
SELECT * FROM util_audit WHERE DATED >= DATE(03/15/2012) AND DATED <= DATE(03/31/2012);
if I just use
SELECT * FROM util_audit WHERE DATED >= DATE(03/15/2012);
It'll return all my record because they were dated this week.
I also tried this:
SELECT * FROM util_audit WHERE DATED >= '02/15/2012 00:00:00' AND DATED <= '03/31/2012 00:00:00';
and nothing! It'll return zero rows, when I know I have all of them dated from the 27 of this month to today. Am I missing something here? why does it work on its own, but not when I add the second date?I'm probably overlooking something.
If you need to select rows from a MySQL database' table in a date range, you need to use a command like this: SELECT * FROM table WHERE date_column >= '2014-01-01' AND date_column <= '2015-01-01'; Of course you need to change: table.
SELECT * FROM PERSONAL WHERE BIRTH_DATE_TIME BETWEEN '2000-01-01 00:00:00' AND '2002-09-18 12:00:00';
select *from yourTableName where yourColumnName between 'yourStartingDate' and curdate().
MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts.
Try:
SELECT * FROM util_audit WHERE `DATED` BETWEEN "2012-03-15" AND "2012-03-31";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With