Blessan Kurien Blessan Kurien - 2 months ago 5
MySQL Question

fetch rows that matches today timestamp in php mysql

I have table in mysql with three fileds

id
name
time_stamp


here
time_stamp
stores php
time()
value.

I want to get the fields that matches todays timestamp ,now i am fetching all rows and check time stamp condition in the loop if it matches will print the current row.

Is there anyway to do this in mysql query itself?

Answer

Since you insert unix timestamps (time()), you don't need to fetch all rows and make a comparison on the fetching. Just use FROM_UNIXTIME() in MySQL:

SELECT * FROM table_name WHERE FROM_UNIXTIME(`time_stamp`, '%Y-%m-%d') = CURDATE()

Fiddle