Thursday 15 September 2011

php - Compare Date in sql table to current date -



php - Compare Date in sql table to current date -

i working on project in dates in sql table needs checked current date. if ticket goes past current date, status of ticket go active expired. not @ php. came with. wrote function @ top of page each time page loads, checks date , compares. date format yyyy-mm-dd. doing wrong. can please help me out?

$result= "select date, status table1"; while($row = sqlsrv_fetch_array($result)){ if(strtotime($row['date']) > strtotime(date('y-m-d'))){ $updatequery = " update table1 set $row[status] = 'expired' "; }}

i advise using php datetime class has date diff function implement this

$today = new datetime('today'); $expires = new datetime($datefromdb); $diff = $today->diff($expires); if($diff < 1) { $updatequery = " update table1 set $row[status] = 'expired' "; }

php sql

No comments:

Post a Comment