Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL Select rows where date is older than datetime

I am coding a status item for a website and need to load statuses older than a variable that contains a datetime.

So the database has a field called added date which is a datetime field and I have a string in datetime format and i want to select all rows older than my datetime format string.

How would this be structured in MYSQL?

Thanks in advance.

like image 321
André Figueira Avatar asked May 12 '12 17:05

André Figueira


3 Answers

 select status_column from your_table
 where added_date < '2012-05-12'
like image 108
juergen d Avatar answered Sep 23 '22 08:09

juergen d


mysql DATETIME type is used for values that contain both date and time parts.

Try this

SELECT datecolumn 
FROM table
WHERE datetime_date > '2012-05-12 01-32-56'
like image 40
Moyed Ansari Avatar answered Sep 23 '22 08:09

Moyed Ansari


try this

$today = date('Y-m-d');

 SELECT column_name FROM table_name WHERE year(added_date) > $today AND month(added_date) > $today
like image 43
M.I.T. Avatar answered Sep 26 '22 08:09

M.I.T.