本文介绍了如何从DDMMYY格式获取月份值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为DATE的列,其中的值就像260713,其中26是DD,07是MM,13是YY。



我想要比较上述日期的特定月份的值。所以我需要像月份和月份这样的东西年价值如



如果日期是2013年7月26日......



I have a column named DATE and values coming into it were like "260713" where 26 is DD, 07 is MM and 13 is YY.

I wanna compare values of particular month from the above date. so i need something like getting month & year values like

If date is 26/07/2013...

MONTH(CONVERT(DATETIME,'26/07/2013')) WHICH GIVES O/P AS '07'
YEAR(CONVERT(DATETIME,'26/07/2013')) WHICH GIVES O/P AS '2013'





如上所示取我月和月的价值从'260713'开始的年份



谢谢..



like as above fetch me values of month & year from date '260713'

Thanks..

推荐答案


declare @var varchar(max)
set @var= '260713'
set @var= '20'+Substring(@var,5,2) + Substring(@var, 3,2) + Substring(@var,1,2)





我在前面加了20,所以它变成了四个字母的年份 - > 2013

现在运行以下内容:



I added the 20 in front so it becomes a four letter year --> 2013
Now running the following:

select @var
select Datepart(month, @var)
select Datepart(year, @var)
select Datepart(day, @var)



这将给你:


which will give you:

20130726
7
2013
26





希望这符合您的要求!



Hope this meets your requirements!



这篇关于如何从DDMMYY格式获取月份值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 21:22