获取设定年份的第一天

Get first day of the set year(获取设定年份的第一天)

本文介绍了获取设定年份的第一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

declare @coyear varchar (max) 
set @coyear = '2018'
SELECT (YEAR(DATEADD(year,0,@coyear))) 

我已将 @coyear 设置为 2018 年,结果为 2018 年.我想要我为一年设置的一年中的第一天.例如,当我在 @coyear 中通过 2018 时,我希望结果为 2018-01-01.

I have set @coyear as 2018 and I am getting 2018 in result. I want first day of the year which I have set for year. For example when I pass 2018 in @coyear I want 2018-01-01 in result.

推荐答案

DATEFROMPARTS 似乎是更好的解决方案:

DATEFROMPARTS would seem a better solution:

DECLARE @CoYear int; --Why would you need 2GB/2 Billion characters for a year?
SET @CoYear = 2018;
SELECT DATEFROMPARTS(@CoYear, 1, 1);

这篇关于获取设定年份的第一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:获取设定年份的第一天

基础教程推荐