Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In SQL how to compare date values?

Using MySQL syntax and having a table with a row like:

mydate DATETIME NULL,

Is there a way to do something like:

... WHERE mydate<='2008-11-25';

I'm trying but not really getting it to work.

like image 738
fmsf Avatar asked Nov 25 '08 19:11

fmsf


2 Answers

Uh, WHERE mydate<='2008-11-25' is the way to do it. That should work.

Do you get an error message? Are you using an ancient version of MySQL?

Edit: The following works fine for me on MySQL 5.x

create temporary table foo(d datetime);
insert into foo(d) VALUES ('2000-01-01');
insert into foo(d) VALUES ('2001-01-01');
select * from foo where d <= '2000-06-01';
like image 99
Eli Avatar answered Oct 04 '22 21:10

Eli


Nevermind found an answer. Ty the same for anyone who was willing to reply.

WHERE DATEDIFF(mydata,'2008-11-20') >=0;
like image 23
fmsf Avatar answered Oct 04 '22 22:10

fmsf