获取当前时间/日期的时间戳

use*_*221 4 php datetime timestamp

我需要使用PHP的简单代码来使用TIMESTAMP获取当前日期/时间并将其插入到数据库中.

我在数据库中有一个名为"ArrivalTime"的字段作为TIMESTAMP.

编辑:

<?php
$con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error());
mysql_select_db("a&e", $con) or die('Could not select database.');
Run Code Online (Sandbox Code Playgroud)

//验证

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

$sql="INSERT INTO Patient(Forename, Surname, Gender, Date_Of_Birth, Address,    Patient_History, Illness, Priority, Arrival_Time)
VALUES('$patient_name', '$patient_lastname', '$gender', '$date', '$address', '$history', '$illness', '$priority', '$time')";
mysql_query($sql,$con) or die('Error: ' . mysql_error());

echo "1 record added";
// close connection 
mysql_close($con);
?>
Run Code Online (Sandbox Code Playgroud)

非常感谢

Ale*_*lex 8

main.php

<?php
    require('connect.php');

    $time = time();


    $sql = "INSERT INTO yourtablename (ArrivalTime) Values ('$time')";
    mysql_query($sql);

    ?>
Run Code Online (Sandbox Code Playgroud)

PS:在sql语句中我确定你需要把其他东西放在其他字段中,所以你只需要替换上面的那个:

$sql = "INSERT INTO yourtablename (field1, field2, ArrivalTime) Values ('$value1','$value2','$time')";
Run Code Online (Sandbox Code Playgroud)

connect.php

<?php

$error = "Couldn't connect";
$connect = mysql_connect("localhost","username","password") or die($error);
mysql_select_db("yourdatabase") or die($error);

?>
Run Code Online (Sandbox Code Playgroud)