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

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

问题描述

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

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'附近的语法不正确。

But I get this Error msg. Incorrect syntax near '10'.

我尝试使用引号

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

我收到此错误消息无法将varchar转换为日期时间

请帮助!
谢谢。

Kindly help! Thanks.

推荐答案

您将要使用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 这是样式对于意大利日期。好吧,不仅是意大利语,而且这是在线图书 a>。

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

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