如何获得帖子的日期和时间?

I got this feedback form I made, and I would like to get the date and time, when a person posted a feedback, and display it next to their name. So, how can I get the date and time?

Here is the code for the form:

<?php
    if(isset($_POST['add'])){
        $name = $_POST['name'];
        $email = $_POST['email'];
        $comment = $_POST['comment'];
        if($name){
            if($email){
                if($comment){
                    mysql_query("INSERT INTO comments (id, name, email, comment) VALUES ('','$name','$email','$comment')");
                    //redirect
                    header("Location: mypage.php");
                }
                else
                    $msg = "You haven't entered any comment!";
            }
            else
                $msg = "You haven't entered an email address!";
        }
        else
            $msg = "You haven't entered your name!";
    }
?>

You could get the date and time at the point of the $_POST of your current system by using:

$curDate = date('Y-m-d H:i:s');

This would return the date/time in the following format: 2015-01-11 13:17:52 - Which you can then store in the database with your INSERT INTO query.

Make sure you have the correct timezone set within PHP as by default it may return UTC time. http://php.net/manual/en/function.date-default-timezone-set.php

Don't change your PHP code, but change your database table: add a column named, say, time, of type TIMESTAMP with as default value CURRENT_TIMESTAMP.

You don't need to change your PHP, the database will automatically put the current time in the new time column when you insert a new record.