Convert a string to date format
Hi I have a field from source file which is in the format 99-OCT-12, i would like to convert this to 19991012. How can i achieve thisSarvan
May 5th, 2011 12:21am

you can do it with Derived Column with expressions, but you need to write a Big conditional expression for convert month name to month number. this is better to do it with script component with two lines of code. (note that you should create an output column of type DT_WSTR or DT_STR for script component. this is the script: DateTime myDate = DateTime.ParseExact(Row.InputColumn, "yy-MMM-dd", System.Globalization.CultureInfo.InvariantCulture); Row.OutputColumn=myDate.ToString("yyyyMMdd"); Note that you should put your input column name instead of INputColumn, and outptu column name instead of OutputColumn. http://www.rad.pasfu.com
Free Windows Admin Tool Kit Click here and download it now
May 5th, 2011 12:31am

Hi Reza Raad, Thanks a lot for your quick turn around. This script helps me to achieve what i require. Also this can be achieved with the below expression which i tried later. I personally prefer derived column expression than script. Input (patdob) : 28-Oct-53 Output : 19531028 Expression : ISNULL(patdob) || TRIM(patdob) == "" ? "" : ((DT_I4)RIGHT(TRIM(patdob),2) <= 11 ? "20" : "19") + RIGHT(TRIM(patdob),2) + RIGHT("00" + (DT_STR,2,1252)DATEPART("MM",(DT_DATE)patdob),2) + RIGHT("00" + (DT_STR,2,1252)DATEPART("dd",(DT_DATE)patdob),2) Sarvan
May 5th, 2011 1:04am

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

Other recent topics Other recent topics