tags:

views:

213

answers:

3

hi , I have a mysql database with a php front end. In my records I have an posted date and an expire date directle access from 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

+1  A: 

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']);

notJim
+1 for DateTime Object
solomongaby
A: 

sir I did as u suggest ,but there is error something like: Catchable fatal error: Object of class DateTime could not be converted to string

amol
Stackoverflow is not like a "common" discussion forum. There are no chronologically ordered message threads. Please use a comment for something like this.
VolkerK
sorry sir,I'm just confused
amol
sir i use mysql database, plz if u have any idea help,thanks once again
amol
This means your string isn't in the format expected by strtotime - use mktime to stitch the parts into a real date and use that for the comparison.
Sohnee
thanks mike sir its working thanks a lot.
amol
A: 

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.