如何以这种格式'MM / dd / yyyy hh:mm:ss'插入日期时间? [英] How to insert datetime like this format 'MM/dd/yyyy hh:mm:ss'?

查看:147
本文介绍了如何以这种格式'MM / dd / yyyy hh:mm:ss'插入日期时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将DateTime插入到'MM / dd / yyyy hh:mm:ss'这样的SQL Server中。

I want to insert my DateTime into SQL Server like 'MM/dd/yyyy hh:mm:ss'.

通常,我形成了以下查询

Generally, I have formed the below query to insert that DateTime in SQL.

insert into tablename values(convert(date,'10/02/2012',110))

它像这样插入 2012-10-02 但我不知道为什么会这样插入?

It inserts like this "2012-10-02" but I don't know why it inserts like this?

我是SQL Server的新手。

I am new to SQL Server.

是否可能以 '02 -10-2016' 这样的美式格式存储?

Is this possible way to store like this '02-10-2016' in US format?

推荐答案

使用此

假定日期列为 date_column ,您可以在显示各种格式的 date_column 时使用转换。请阅读随附的参考资料,以了解各种格式。

Assuming the date column is date_column, you can use convert while displaying the date_column in various formats. Read the attached reference for various formats.

SELECT CONVERT(VARCHAR(10), date_column, 110) AS [MM-DD-YYYY] from tablename;

编辑:由于我之前看错了问题,因此将日期格式从意大利语更正为美国。

Corrected the date format from Italian to US as I misread the question earlier.

http://www.sql-server-helper.com/sql-server-2008/sql-server-2008-date-format.aspx

这篇关于如何以这种格式'MM / dd / yyyy hh:mm:ss'插入日期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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