2

I have a MySQL database with a PHP front end. In my records I have a posted date and an expire date directly accessed from the database. What I need to do is check and see if any records expire date matches posted date.

Something like:

<?php $posted_date= $row_Recordset1['date_posted']; ?>
<?php $exp_date= $row_Recordset1['expire_date']; ?>      

<?php if ($posted_date("Y-m-d") >= $exp_date("Y-m-d")) {
    //statement
<?php  } ?>
BartoszKP
  • 34,786
  • 15
  • 102
  • 130
amol
  • 47
  • 1
  • 2
  • 10
  • $row_Recordset1 sounds like a database result. Which rdbms is it? What's the format of the date values? (`echo $row_Recordset1['date_posted'];`) – VolkerK Sep 30 '09 at 07:25

2 Answers2

1

You can turn them into Unix timestamps using strtotime, assuming they start out as a string, and then they'll just be integers, which you can compare. Another option would be to use DateTime objects, which can be compared using comparison operators. If your date is represented as a format strtotime understands, you can do $dt=new DateTime($row_Recordset1['expire_date']);

davidtbernal
  • 13,434
  • 9
  • 44
  • 60
1

You could do this:

$posted_date= $row_Recordset1['date_posted'];
$exp_date= $row_Recordset1['expire_date'];      

if (strtotime($posted_date) >= strtotime($exp_date)) {
    // Do whatever
}

This would work assuming that dates from the DB are the standard formated date strings.

Mike A.
  • 398
  • 3
  • 12