Posted By

MMDeveloper on 03/25/09


Tagged

date mssql String part sub


Versions (?)

MSSQL 2 digit representation of next year


 / Published in: SQL
 

Had to write this for work to automatically convert current year's 2-digit value to a string containing current year's 2-digit value and next years's 2-digit value.. for example:

0607, 0708, 0809, 0910

This assumes that the table column that contains the current year's 2-digit representation is called "SSSSY2"

  1. SUBSTRING(CAST(DATEPART(year ,
  2. DATEADD(year , 1 ,
  3. '01/01/' + CAST(s.[SSSSY2] AS CHAR(2)))) AS CHAR(4)) ,
  4. 3 , 2)

Report this snippet  

You need to login to post a comment.