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

编程入门 行业动态 更新时间:2024-10-27 22:33:39
本文介绍了获取当前时间/日期的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I need simple code using PHP to get the current date/time using TIMESTAMP and insert this into a database.

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

I have a field called "ArrivalTime" within a database as 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.');

//验证

$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); ?>

非常感谢

推荐答案

main.php

<?php require('connect.php'); $time = time(); $sql = "INSERT INTO yourtablename (ArrivalTime) Values ('$time')"; mysql_query($sql); ?>

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

P.S: in the sql statement i'm sure you'll need to put other things in the other fields ,so you just replace the one above by this:

$sql = "INSERT INTO yourtablename (field1, field2, ArrivalTime) Values ('$value1','$value2','$time')";

connect.php

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

更多推荐

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

本文发布于:2023-10-16 12:31:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497562.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间   日期

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!