Forum Moderators: coopster

Message Too Old, No Replies

help with date/time - determining expiry date

         

adammc

4:43 am on Sep 27, 2006 (gmt 0)

10+ Year Member



Hi guys,

I was hoping for some help if possible?

I need to find a way to mark entries in the MYSQL DB as expired once the expired date has passed.

I plan on putting some code on the top of my front page so it can make this check whenever my site is loaded.

example of data in expiry_date column
2006-09-20 13:28:10

I am using a function to get the current date (it is stored in $currentdatetime variable), it is oputputting the date as:
2006-09-27 14:29:08

Would I use '<' Less than?

[php]
// run the query
$SQL = " UPDATE postings SET status = 'expired' WHERE expiry_date < LESS THAN? $currentdatetime";
[/php]

adammc

5:06 am on Sep 27, 2006 (gmt 0)

10+ Year Member



Nevermind, i figured it out using this:

[php]
$SQL = " UPDATE postings SET status = 'expired' WHERE expiry_date < '$currentdatetime3'";
$R = @mysql_query ($SQL);

// check for error
if (!$R) { echo("ERROR: " . mysql_error() . "\n$SQL\n");

// Show errors, if any
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

}

[/php]

Psychopsia

5:09 am on Sep 27, 2006 (gmt 0)

10+ Year Member



Hi!

Yes, the query works, but can remove the quotes around the $currentdatetime:

$sql = "UPDATE postings SET status = 'expired' WHERE expiry_date < $currentdatetime3";

adammc

5:11 am on Sep 27, 2006 (gmt 0)

10+ Year Member



Can I ask why you are recommendeding that?

Psychopsia

5:14 am on Sep 27, 2006 (gmt 0)

10+ Year Member



Because $currentdatetime is an int and the expiry_date field is int too, right?
Or am i wrong?

[edited by: Psychopsia at 5:16 am (utc) on Sep. 27, 2006]