开发者

How to code auto set date and time in php

开发者 https://www.devze.com 2023-03-18 18:58 出处:网络
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 t

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号