字符串DateTime格式为月 [英] String DateTime format to month

查看:72
本文介绍了字符串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格式为月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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