How to code auto set date and time in php
Attribute DateAdded
is example of auto set date and time, Any one can show me how to do auto set date and time. What I want is if I submit new insert form in my system, date and time will be show in the database.
example data in database
DateAdded = 2011-07-28开发者_运维问答 11:17:09
Try with:
$DateAdded = date( 'Y-m-d H:i:s' );
MySQL solutions
Use timestamp
, While you creating DateAdded coulmn
or
Use Now()
in insert Query
You could do:
$dateAdded = date( 'Y-m-d H:i:s' );
or your database function to get the current time function, like 'NOW()
' or 'SYSDATE()
'.
You can set that in the column property itself. On creating the table just add the property ON UPDATE CURRENT_TIMESTAMP
, and then whenever the a row is inserted, the time will be updated automatically. For further details check the manual
精彩评论