6

I have string coming in through an SSIS package via text file in form:

"20090910" (string)

and it needs to be

2010-09-01 00:00:00 (Date)

Any suggestions?

1 Answer 1

11

Try DateTime.ParseExact()

Example from MSDN with your data:

Dim dateString, format As String  
Dim result As Date
Dim provider As Globalization.CultureInfo = Globalization.CultureInfo.InvariantCulture

' Parse date and time with custom specifier.
dateString = "20090910"
format = "yyyyMMdd"        
Try
   result = Date.ParseExact(dateString, format, provider)
   Console.WriteLine("{0} converts to {1}.", dateString, result.ToString())
   Console.ReadLine()
Catch e As FormatException
   Console.WriteLine("{0} is not in the correct format.", dateString)
End Try 
Sign up to request clarification or add additional context in comments.

6 Comments

it doesn't seem to like this. ssis gives really obscure errors and i can't step through code in a script component
it says : Conversion from string "2"" to type 'Double' is not valid.
i imported system.globalization
Can you edit your post to include the full error that SSIS gives you? Stack trace and all. Most important is the line number that the error reports, and then statement on the corresponding line number. It appears that the error isn't related to the datetime parsing, but it's not clear.
Ugh, it seems that I fixed the problem, there were quotations coming in around the string "2009.." so i did a string.replace to take them out and it works now. sorry for wasting your time.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.