Converting a string to datetime from "yyyy-MM-dd"

c#, datetime-format, sql-server

Solution

I would prefer to be able to convert the variable to datetime before I have to open my SQL connection, if possible.

DateTime result = DateTime.ParseExact("2012-04-05", "yyyy-MM-dd", CultureInfo.InvariantCulture);

Problem

Even though it seems like this question has been asked a bunch of times, I can't seem to find an answer that is specific to my question: I have a variable that is read from an XML file by a C# XML parser. It is a string, and is in the format `"yyyy-MM-dd"`. I would like to read this variable into our database using `SQL`, but it needs to be in the proper datetime format in order for me to do this. Unfortunately, I can't find any datetime formats for `"yyyy-MM-dd"`. Am I missing something? I would prefer to be able to convert the variable to datetime before I have to open my `SQL` connection, if possible.

Original source