Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql time stamp queries

I have a column that uses time stamp. My question is I am a bit confused about how to make queries against it,how would I say

Where $time is after X date

Are queries made in local time or CUT?

When I just try to do where andthe post date /time I get an error because of the space and if I quote it I think it takes it as a string : /

What format do I use for the date in the WHERE clauss !?!?

like image 360
James Andino Avatar asked Sep 08 '10 06:09

James Andino


2 Answers

You can use the normal logical comparisons, for example:

SELECT * FROM table WHERE date >= '2010-01-31'
SELECT * FROM table WHERE date >= '2010-01-31 12:01:01'

Time is generally in your current local time, but you can run the query "SELECT CURTIME()" to check. Also, make sure you have the year-month-date in the right order... that can cause issues.

The manual has more details:

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

like image 142
Adam Morris Avatar answered Sep 21 '22 19:09

Adam Morris


Assuming you talk about TIMESTAMP column type (not Unix timestamp) the format is either 'YYYY-MM-DD HH:MM:SS' (quoted) or YYYYMMDDHHMMSS

Atually, in the first case you can use any spearators you wish (or none), only numbers are taken into ccount

like image 20
Mchl Avatar answered Sep 22 '22 19:09

Mchl