Jump to content

[SOLVED] Query. Trying to select all rows less than 1 day old using date field


hellonoko

Recommended Posts

I am trying to write a query that selects all rows entered less than a day ago by comparing the field that states when the row was created against the current date/time minus 1 day.

 

What is the proper way to do this as my query is failing.

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/sharingi/public_html/scrape/display/display.php on line 167

 

<?php


	$current_time = strtotime("now");

	//take one day in seconds from the current time to find the timestamp for 24 hours ago
	$day_old = $current_time - 86400;			

	//change timetamp to a date format to compare
	$day_old = date("Y-m-d H:i:s", $day_old);

	echo $day_old;
	// select all entries that are less than the 1 day old
	$query = mysql_query("SELECT * FROM `mp3links` WHERE `foundtime` < $day_old AND `scraped` != '0' ORDER BY `foundtime` DESC");

?>

 

 

Link to comment
Share on other sites

Query fails for some reason. Try displaying mysql error message

$query = mysql_query("SELECT * FROM `mp3links` WHERE `foundtime` < $day_old AND `scraped` != '0' ORDER BY `foundtime` DESC") or die(mysql_error());

to see why

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.