Saurabh Singh
Saurabh Singh

Reputation: 31

mysql search by time on time stamp

I am stuck with this issue for a while now any solutions are welcomed.

I have a table in MySQL and i am storing a timestamp.

Now lets say if i search on the basis of only date it works.

SELECT *
FROM   table
WHERE  timestamp > "2012-03-12";

this fetches all data where timestamp value is greater than 2012-03-12 00:00:00.

what i want is a query like this :

SELECT *
FROM   table
WHERE  timestamp > "10:20:09";

where all records with tie greater than 10:20:09 is fetched irrespective of the date.

Upvotes: 1

Views: 3706

Answers (1)

PoeHaH
PoeHaH

Reputation: 1936

Use this statement (it will get the time from your datetime column and compare it with the time)

SELECT *
FROM   table
WHERE  DATE_FORMAT(yourDatecolumn, '%H:%i:s') > '10:20:00'

Warning This time format is for EU times (where 1pm = 13), if you want US format, use '%h:%i:s'

Upvotes: 6

Related Questions