在 SQL Server 中插入日期时间的 Sql 查询 [英] Sql query to insert datetime in SQL Server

查看:75
本文介绍了在 SQL Server 中插入日期时间的 Sql 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用下面的 sql 查询将 datetime 值插入到表(SQL Server)中

I want to insert a datetime value into a table(SQL Server) using the sql query below

insert into table1(approvaldate)values(18-06-12 10:34:09 AM);

但我收到此错误消息.'10' 附近的语法不正确.

我用引号试过了

insert into table1(approvaldate)values('18-06-12 10:34:09 AM');

我收到此错误消息 Cannot convert varchar to datetime

请帮忙!谢谢.

推荐答案

您将需要使用 YYYYMMDD 在 SQL Server 中确定日期.

You will want to use the YYYYMMDD for unambiguous date determination in SQL Server.

insert into table1(approvaldate)values('20120618 10:34:09 AM');

如果您使用 dd-mm-yy hh:mm:ss xm 格式,则需要使用具有特定样式的 CONVERT.

If you are married to the dd-mm-yy hh:mm:ss xm format, you will need to use CONVERT with the specific style.

insert into table1 (approvaldate)
       values (convert(datetime,'18-06-12 10:34:09 PM',5));

5 这是意大利日期的样式.嗯,不仅是意大利人,这也是 在线图书.

这篇关于在 SQL Server 中插入日期时间的 Sql 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆