本文介绍了将字符串'04 / 13'转换为sql中的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HI朋友,,
如何将字符串'04 / 13'(即2013年4月)转换为日期格式'dd / mm / yyyy'。
HI Friends,,
How to convert a string '04/13' which means April/2013 to a date format 'dd/mm/yyyy'.
推荐答案
DECLARE @shortdate VARCHAR(10)
--needed to successful conversion
SET DATEFORMAT dmy;
--your input string
SET @shortdate = '04/13'
--valid date
SELECT CONVERT(DATETIME, '01/' + @shortDate) AS myDate
更多: []
[]
SELECT CONVERT(DATETIME, '01/04/13', 3)
如果没有day参数,则无法转换为datetime。
You can't convert to datetime without the day parameter.
这篇关于将字符串'04 / 13'转换为sql中的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!