一个字符串从"转换为datetime; YYYY-MM-DD" [英] Converting a string to datetime from "yyyy-MM-dd"
问题描述
虽然它看起来像这个问题已经被问了一堆的时候,我似乎无法找到一个答案是具体到我的问题:
我有一个从XML文件由C#XML解析器读取变量。这是一个字符串,格式为YYYY-MM-DD。我想读这个变量将使用SQL我们的数据库,但它需要在适当的日期时间格式,以便为我做到这一点。不幸的是,我找不到任何日期时间格式YYYY-MM-DD。我缺少的东西吗?
我宁愿能够将变量转换为DATETIME之前,我不得不打开我的SQL连接,如果可能的话。
我宁愿能变量为DateTime转换我之前
已经打开我的SQL连接如果可能的话。
块引用>
DateTime的结果= DateTime.ParseExact(2012-04-05 YYYY-MM-DD,CultureInfo.InvariantCulture);
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.
解决方案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);
这篇关于一个字符串从"转换为datetime; YYYY-MM-DD"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!