| Title: | PHP and MySQL date data type |
|---|---|
| Author: | Mark Kiehl |
| Category: | PHP |
| MySQL date Setup MySQL table weith field/column `last_visit` as follows: Type: date Null: Yes Default: NULL INSERT or UPDATE the table field `last_visit` as follows in PHP: <?php ... $my_last_visit = date("Y-m-d",time()); $sql = "UPDATE `tableName` SET `last_visit`='".$my_last_visit."'" ... ?> When retrieving values, execute select query <?php ... $rec = mysql_fetch_array($result) or Die("mysql_fetch_array error ".mysql_error()); echo 'Your last visit was on '.date('d M Y',strtotime($rec['last_visit'])).' or '.round((time()-strtotime($rec['last_visit']))/(60*60*24),0).' days ago.'; ... ?> |