Blessan Kurien Blessan Kurien - 1 year ago 57
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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download