Delete rows where expiration falls before current time SQL

Hi there,
I am writing a PHP script that manipulates a database, and I am calculating an expiration date of my user’s requests, as they supply a duration (in minutes) for the request, and once that date lapses, I no longer want the request in my database. Here is the code I am using to generate the date:
$expires = floor($_GET['duration']/60) .':'. $_GET['duration']%60 .':0';
Then I am adding the duration to the time at which the request is submitted. My problem occurs when I go to remove the rows from my database. Currently, my SQL statement to delete these rows is as follows:
$sql = "DELETE FROM table WHERE UNIX_TIMESTAMP(Expiration) < NOW()";
This query appears to be removing all of the rows when it is run, not just the ones that are expired. Does anybody have any ideas as to what is causing this?

Never mind, figured it out. Apparently mysql’s NOW() function returns a datetime, not a timestamp.

2 Likes

Good job and well done :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.