Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql select query after certain date

Tags:

I am trying to pull records after a certain date using mysql query , the field type is date in my database and the query is

SELECT * FROM tickets WHERE created_on > 26-08-2011 

But it is not working and also showing all before that date

Thanks

like image 858
Henry Avatar asked Aug 30 '11 21:08

Henry


People also ask

How do I select a specific date in MySQL?

You can use DATE() from MySQL to select records with a particular date. The syntax is as follows. SELECT *from yourTableName WHERE DATE(yourDateColumnName)='anyDate'; To understand the above syntax, let us first create a table.

How do I query a specific date in SQL?

You just need to tell the processor what format the date/time is in: Select * from Table where date Between to_date('2009-05-24 06:15:00', 'yyyy-mm-dd hh24:mi:ss') and to_date('2009-05-24 08:15:00 ', 'yyyy-mm-dd hh24:mi:ss').

How do I query between two dates using MySQL?

select *from yourTableName where yourColumnName between 'yourStartingDate' and curdate().

How do I pass a date range in SQL query?

SELECT * FROM PERSONAL WHERE BIRTH_DATE_TIME BETWEEN '2000-01-01 00:00:00' AND '2002-09-18 12:00:00';


1 Answers

The date you are using is a string, so it needs to be placed inside quotes. Also, the format is the wrong way around:

SELECT * FROM tickets WHERE created_on > '2011-08-26' 

For more information, see the MySQL docs. In particular, note the very first line:

The format of a DATE value is 'YYYY-MM-DD'. According to standard SQL, no other format is permitted.

like image 74
James Allardice Avatar answered Jan 01 '23 21:01

James Allardice