且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-01-28 23:41:38

假设@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).