Reputation: 950
I need to output a list of the records created in the last 24 hours (keyword hours, not last day) from a mysql table via php. I have a column in the table labled 'timestamp' that is set to default CURRENT_TIMESTAMP.
I'm trying something along the lines of:
<?php
$sql="SELECT * FROM list WHERE timestamp > I-have-no-clue-what-to-put-here";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){
echo $row['itemname'] . " " . $row['itemurl'];
}
?>
Am I headed in the right direction?
Upvotes: 0
Views: 1969
Reputation: 26617
SELECT * FROM list WHERE timestamp > DATE_SUB(now(), INTERVAL 1 DAY)
See docs for DATE_ADD and DATE_SUB.
Upvotes: 6