Sign in to follow this  
bmorency

php and mysql. retrieving records older than 10 minutes

Recommended Posts

Hi, I am kinda new to mysql and I am writing a php function to retrieve records that are older than 10 minutes old. I have been spending a lot of time on this function and nothing is working for me. I have a column that is a DATETIME type called 'datetime' that has the date and time the record was entered into the DB. Here is the query i am using. $query = "SELECT * FROM ".usertable." WHERE DATE_SUB(CURDATE(),INTERVAL 10 MINUTE) > datetime"; i am not sure why nothing is getting deleted. if I switch the greater than sign to a less than sign it will clear the table even though some records can be less than 10 minutes old. Does anyone have any idea what the problem could be? thanks for any help.

Share this post


Link to post
Share on other sites
sorry. i forgot to mention that the records that should be getting returned using this select statement are being deleted by a delete function that I have made. they are not being deleted by this select statement.

Share this post


Link to post
Share on other sites
Try storing date & time as a BIGINT. I find this datatype much easier to work with especially when calculating differences between 2 timestamps.

In PHP..
$time = time(); // get time as long int

// covert to string eg: '26/5/2005 5:26 pm'
$date_str = date("d/m/y g.i a", $time);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this