加入收藏 | 设为首页 | 会员中心 | 我要投稿 航空爱好网 (https://www.52kongjun.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SQL Server 日期 字符串 格式转换 函数 datetime conve

发布时间:2022-11-22 13:31:56 所属栏目:MsSql教程 来源:未知
导读: 文章目录Intro
对某些表格数据进行查询时,常常有按照时间进行列值过滤的需求。
SQL
SQL Server 内置函数CONVERT(data_type(length),data_to_be_converted,style)
常见的两种转换需求: 1.

文章目录Intro

对某些表格数据进行查询时,常常有按照时间进行列值过滤的需求。

SQL

SQL Server 内置函数CONVERT(data_type(length),data_to_be_converted,style)

常见的两种转换需求: 1. 日期 –> 字符串

2. 字符串 --> 日期 

复制

select getdate();	-- datetime
-- datetime --> string
declare @datetimeValue datetime = getdate();
select @datetimeValue,
convert(nvarchar(30), @datetimeValue, 120),
convert(nvarchar(30), @datetimeValue, 121),
convert(nvarchar(30), @datetimeValue, 126);
-- string --> datetime
declare @strValue nvarchar(30) = '2021-06-20 08:49:09.090';
select convert(datetime, @strValue, 121);

复制

Others

(编辑:航空爱好网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!