All for Joomla All for Webmasters

SQL SELECT DATE

SQL SELECT DATE is used to retrieve a date from a database. If you want to find a particular date from a database, you can use this statement.

For example: let’s see the query to get all the records after ‘2013-12-12’.

  1. SELECT * FROM
  2. tablename WHERE your datecolumn >= ‘2013-12-12’

Let’s see the another query to get all the records after ‘2013-12-12’ and before ‘2013-12-13’ date.

  1. SELECTFROM
  2. tablename where your datecolumn < ‘2013-12-13’ and your datecolumn >= ‘2013-12-12’

If you want to compare the dates within the query, you should use BETWEEN operator to compare the dates.

  1. SELECT * FROM
  2. table_name WHERE yourdate BETWEEN ?2012-12-12? and ?2013-12-12?

Or if you are looking for one date in particular you can use. You should change the date parameter into the acceptable form.

  1. SELECTFROM
  2. table_name WHERE cast (datediff (day, 0, yourdate) as datetime) = ?2012-12-12?
PinIt
submit to reddit

Leave a Reply

Top