Converting a date CYYMMDD to and from

 

I ran into a customer using the old Y2K Date that I hhadn’t seen for a while and thought that I would take a moment to blog how to convert to and from.

TO : 

CASE WHEN SUBSTRING(CAST(dKey_TimeByDay AS VARCHAR),1,1) = 2 THEN ‘1’+

SUBSTRING(CAST(dKey_TimeByDay AS VARCHAR),3,6)

 ELSE ‘0’ +

SUBSTRING(CAST(dKey_TimeByDay AS VARCHAR),3,6)

END

 

FROM :
Convert(DateTime, Convert(VarChar(8), EV200_START_DATE + 19000000)) 

Leave a Reply