locked
SSIS Script task - c# RRS feed

  • Question

  • Hi .

    I using script task to check if a excel row is a valid date and then split the date into MM ,DD, YYYY.

    I have an existing vbscript code , which is of the below:

    if DATE_FORMAT_YYYYMMDD =  SniffDateFormat( f6 ) Then
    f6 = Mid( f6, 5, 2 ) & "/" & Right( f6, 2 ) & "/" & Left( f6 , 4 )
     else
     f6 = Month(f6) & "/" & Day(f6) & "/" & Year(f6)
    end if


    Function FixDate( szDate )
    
    	FixDate = szDate
    
    End Function
    
    'Date Formats
    CONST DATE_FORMAT_YYYYMMDD = 1
    CONST DATE_FORMAT_UK   = 2
    CONST DATE_FORMAT_UNKOWN = 99
    
    Function SniffDateFormat( szDate )
    
        ' 20/12/2006    - UK
        ' 20061220      - YYYYMMDD
          
        If IsYYYYMMDD( szDate ) Then
            SniffDateFormat = DATE_FORMAT_YYYYMMDD 
            Exit Function
         End If    
         
         SniffDateFormat = DATE_FORMAT_UK  
    
    End Function
    
    Function IsYYYYMMDD( szDate )
    
        If 8 <> Len ( szDate ) Then
            IsYYYYMMDD = False
               Exit Function
        End If
    
        dim yr, mn, dy
        yr = left( szDate, 4 )
        mn = mid( szDate, 5, 2 )
        dy = Right(szDate, 2 )
        
        if (yr < 1900 OR  yr > 3000) then   
            IsYYYYMMDD = False
            Exit Function
        end if
    
        if (mn < 0 OR mn > 12) then 
            IsYYYYMMDD = False
            Exit Function
        End if
        
        if (dy < 0 OR dy > 31) then
            IsYYYYMMDD = False
            Exit Function
        End If
            
        IsYYYYMMDD = True
            
    End Function

    I need help to convert this VBScript code to C#?

    Thanks

    Friday, March 27, 2020 9:20 AM

Answers

  • Hi Venkatzeus,

    We can use VB script in SSIS Script Task.

    If you want to convert VB script to C#, please refer to free 3rd party tool: https://converter.telerik.com/ .

    Best Regards,

    Mona


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, March 30, 2020 1:37 AM