字符串DateTime格式为月

编程入门 行业动态 更新时间:2024-10-28 19:21:52
本文介绍了字符串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格式为月

本文发布于:2023-05-30 15:31:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/371055.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   格式为   DateTime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!