如何从SQL Server中的已知月份和年份获取日期格式 [英] how to get date format from known month and year in sql server

查看:144
本文介绍了如何从SQL Server中的已知月份和年份获取日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

如何从SQL Server中的已知月份和年份获取日期格式

例如:我必须使用第5个月和2011年形成一个日期.新的格式应为日期05/01/2011.

如何获得

在Advance中致谢

Hi all

how to get date format from known month and year in sql server

eg: i have to form a date using month 5 and year 2011..the new should be in format date 05/01/2011.

how to get it

Thanks in Advance

推荐答案

假设@month = 5,@ year = 2011并且是整数:

Assuming @month = 5, and @year = 2011 and are integers:

SET DATEFORMAT dmy;
DECLARE @myDate DATETIME;
DECLARE @dateString varchar(10);
SET @dateString = CONVERT(int, @month) + ''/01/'' + CONVERT(int, @year);
SET @myDate = CONVERT(DateTime, @dateString);



可能有更好的方法,但这应该可行(我只是在脑海中打了一下,所以您可能需要对其进行调整).



There are probably better ways to do it, but this should work (I just typed it off the top of my head, so you may need to tweak it).


这篇关于如何从SQL Server中的已知月份和年份获取日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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