Scott Lock

Thoughts on .Net, Caparea.net and Windows Phone


News

My Stats

  • Posts - 77
  • Comments - 134
  • Trackbacks - 21

Tag Cloud


Recent Comments


Recent Posts


Archives


Post Categories


Image Galleries


Blogs I Read


Microsoft MVP


User Groups



I ran accross a field in a flat file yesterday that was in the format of "CCYYDDD".  Now I can only assume that "CC" means century, but that's not the point.  The actual value was "2008294".  I needed to write an expression that converted the year and day of year format to a standard date.  Here's the expression to do this (thank you to Ed Buhain for brainstorming):

DATEADD("d", ((DT_I4)SUBSTRING(Date, 5, 3) - 1), (DT_DATE)("1/1/" + SUBSTRING(Date, 1, 4)))

Where "Date" is the value you need to convert.

Pretty straight forward.  Just subtact 1 from the day of year value and add to January 1st using DateAdd.  The end result in this case is "10/20/2008"

 


Comments

Gravatar # re: Converting Day of Year and Year to Date in SSIS
Posted by Marc Brooks on 2/13/2009 2:30 PM
Elegant and simple. Nice.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: