本文介绍了字符串DateTime格式为月的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在SQL Server 2008中从给定的字符串变量中获取两位数表示的月份. 例如:声明@date varchar(50) 设置@date =''2012年2月15日'' 我只需要输出 -------- 02
How to get the month with two digit from given string variable in SQL Server 2008. Ex:Declare @date varchar(50) set @date=''15/02/2012'' I need output only -------- 02
推荐答案使用 DatePart函数 SELECT DATEPART(yyyy,OrderDate) AS OrderYear, DATEPART(mm,OrderDate) AS OrderMonth, DATEPART(dd,OrderDate) AS OrderDay, FROM Orders WHERE OrderId=1
尝试使用此 Try With This Declare @date varchar(50) set @date=cast(month('15-Feb-2012') as nvarchar(50)) Select @Date
更多推荐
字符串DateTime格式为月
发布评论