Date and Time Format in SSIS

I have a date and time format:

Interval Start Time
1/13/16 1:30:00 
1/15/16 10:30:00

Desired Result

Interval Start Time
13/01/2016 13:30:00 (24 Hr)
15/01/2016 10:30:00

The time interval is between 08:00 and 17:30.

I would like it to be: 01/13/2016 13:30 and 01/15/2016 10:30:00, and I designed this in a column derived from SSIS:

 (DT_DATE)(SUBSTRING([Interval Start Time],3,2) + "-" + 
 SUBSTRING([Interval Start Time],1,1) + "-" + 
 SUBSTRING([Interval Start Time],6,2) + " " +  
 SUBSTRING([Interval Start Time],9,1) == 1 ? "13" : 
 SUBSTRING([Interval Start Time],9,1) == 2 ? "14" :
 SUBSTRING([Interval Start Time],9,1) == 3 ? "15" : 
 SUBSTRING([Interval Start Time],9,1) == 4 ? "16" :  
 SUBSTRING([Interval Start Time],9,1) == 5 ? "17" : 
 "[Interval Start Time]" )
 + ":" + SUBSTRING([Interval Start Time],11,2))

Error in SSIS:

... An expression may contain an invalid token, an incomplete token, or an invalid element ...

and I'm not sure if this formula is correct in what I want to do. Any help would be greatly appreciated.

+4
source share
1 answer

, , . , , , Interval Start Time (10) (12) , , SUBSTRING .

: Script.

  • Script .
  • Script, Interval Start Time, Input Columns.
  • , , , (DT_DBTIMESTAMP). enter image description here
  • Script Script...
  • , Input0_ProcessInputRow.

    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        /*
        * Add your code here
        */
        var str_timestamp = Row.IntervalStartTime.ToString();
        string[] arr = str_timestamp.Trim().Split(' ');
        string[] date = arr[0].Split('/');
        string[] time = arr[1].Split(':');
    
        string formatedDate = "20" + date[2] + "-" + date[0].PadLeft(2, '0') + "-" + date[1].PadLeft(2, '0');
        int hour = Convert.ToInt32(time[0]);
        int hour_24 = hour < 8 ? hour + 12 : hour;
        formatedDate += " " + hour_24 + ":" + time[1] + ":" + time[2];
    
        Row.MyColumn = Convert.ToDateTime(formatedDate);
    
    }
    
  • Row.MyColumn MyColumn .

  • Visual Studio .

Script, IntervalStartTime .

enter image description here

, .

+1

Source: https://habr.com/ru/post/1649770/


All Articles