如何使用php在SQLSRV中只插入时间
目前我有2个变量接收形式的javascript函数
$date = $_POST['date'];//datevariable = x/xx/xxxx > string
$time = $_POST['time'];//timevariable = xx:xx > string
and my table is
dates = date
times = time(7)
和我得到一个错误,而我已经尝试插入到数据库它说数据类型错误
那么什么是正确的数据类型日期/时间格式为我的表?或任何其他方式获得当前时间/日期插入到表中?
谢谢
或任何其他方式获得当前时间/日期插入到表中?
可以使用SQL Server GETDATE()函数。https://msdn.microsoft.com/en-us/library/ms188383.aspx
CREATE TABLE [dbo].[mytimetable] (
[d] [date] NULL
,[t] [time](7) NULL
)
DECLARE @now DATETIME = getdate()
INSERT INTO mytimetable (
d
,t
)
VALUES (
@now
,@now
)
SELECT *
FROM mytimetable
d t
---------- ----------------
2015-08-09 22:46:07.0470000
(1 row(s) affected)