How can I insert the current time into the table?

Source: Internet
Author: User
Previously, the following code inserts data. Now the table has added a time column type of TIMESTAMP. I just want to insert the time when data is submitted to the table. How can I change this code below?? Just change it here? {Code ...} previously, the following code inserts data. Now the table has added a time column type of TIMESTAMP. I just want to insert the time when data is submitted to the table. How can I change this code below?? Just change it here?

$stmt=$pdo->prepare("insert into blog(tid,title,content,name)values(:tid,:title,:content,:name)");$stmt->execute($_POST);

Reply content:

Previously, the following code inserts data. Now the table has added a time column type of TIMESTAMP. I just want to insert the time when data is submitted to the table. How can I change this code below?? Just change it here?

$stmt=$pdo->prepare("insert into blog(tid,title,content,name)values(:tid,:title,:content,:name)");$stmt->execute($_POST);

In PHP. ini, the date. timezone option is used to set the time zone, but the time zone is disabled by default.
PHP explains that the display time is "Greenwich Mean Time", which is 8 hours different from our local time ---------The time zone must be correct.

The NOW () function returns the current date and time with ''yyyy-MM-DD HH: MM: s'' and can be saved directly to the DATETIME field.

CURDATE () returns today's DATE in 'yyyy-MM-DD 'format and can be saved directly to the DATE field.

CURTIME () returns the current TIME in 'hh: MM: ss' format and can be saved directly to the TIME field.

  1. Mysql statementinsert into xxxx (addDateTime) values (now())
    2. mysql statement 'insert into now (id, nowtime) values ('1', NOW ())

Remember to manually correct the time difference as follows:
$ Timeoffset = 8;
Echo gmdate ("Y-m-d H: I: s", mktime () + $ timeoffset * 3600 )."
";
Echo gmdate ("Y-m-d H: I: s", time () + $ timeoffset * 3600 )."
";
Echo date ("Y-m-d H: I: s", mktime () + $ timeoffset * 3600 )."
";
Echo date ("Y-m-d H: I: s", time () + $ timeoffset * 3600 )."
";
Output Format: 17:41:58
$ T = gmdate ("Y-m-d H: I: s", mktime () + 8*3600)
$ SQL = "insert into xxxx (addDateTime) values ($ t )"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.