year less then 49

Hi All,

For dates, why do we need to check whether the year is less than 49 criteria. if it is less than 49 then 19 else 20?

Thanks

April 28th, 2014 3:17am

Try

select case when YEAR(getdate())<49 then 19 else 20 end

Free Windows Admin Tool Kit Click here and download it now
April 28th, 2014 4:04am

Thanks for reply Hua,

My question is why do we need this criteria like if year < 2049 then 19__ else 20__?

April 28th, 2014 4:17am

You need case when ... end to achieve that.
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2014 4:36am

I do not want to achieve this. I can achieve this :). But my question is, is it necessary to make such condition while building date condition.

Refer following link for to get more clarity.

http://social.msdn.microsoft.com/Forums/sqlserver/en-US/12c17b96-2260-459b-9b9e-dd6885469838/calculating-date-formate-with-a-number?forum=sqlgetstarted

can I make only that query as

DECLARE @dt VARCHAR(10)
SET @dt = '201403'
SELECT @dt, LEFT(@dt,2)+ '-'+RIGHT(@dt,2) + '-'+SUBSTRING(@dt,3,2)


 

 

 

April 28th, 2014 4:47am

I suggest you define the field as a datetime and then check against the year of it like what I showed to you.
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2014 4:59am

Hi,

This criteria is required when using 2 digit year. i.e. When you user 2 digit year 35, it can either mean 1935 or 2035.

By default SQL Server uses 2049 as cut off, meaning that 01 to 49 are considered as 2001 to 2049.

and anything greater than 49 is considered as 1949, 1950...

Other applications may have different cut off year, so instead of using 2 digit always use 4 digit

April 28th, 2014 5:05am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics