将字符串'04 / 13'转换为sql中的日期格式 [英] converting a string '04/13' to a date format in sql

查看:65
本文介绍了将字符串'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'.

推荐答案

试试这个:

Try this:
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





更多:设置日期格式 [ ^ ]

CAST AND CONVERT [ ^ ]


你好,



你需要添加day参数:

Hello,

You'll need to add the day parameter :
SELECT CONVERT(DATETIME, '01/04/13', 3)



如果没有day参数,则无法转换为datetime。


You can't convert to datetime without the day parameter.


这篇关于将字符串'04 / 13'转换为sql中的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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