我有这段代码:
string testdate = File.GetCreationTime(filePath + file).ToString("yyyy-MM-dd HH:mm:ss.fff");
DateTime test1 = DateTime.ParseExact(testdate, "yyyy-MM-dd HH:mm:ss.fff", new CultureInfo("en-US"), DateTimeStyles.None);
Run Code Online (Sandbox Code Playgroud)
在testdate上我有以下日期: 2017-12-15 09:57:20.626
现在,当我尝试将其解析为datetime时,结果如下:
测试1: 12/15/2017 9:57:20 AM
我想要的结果是testdate上的确切日期,但作为DateTime变量
如果我使用HH作为24小时格式,为什么会发生这种情况?我已经看过许多帖子删除AM和PM,但是使用字符串,我需要它作为查询的日期时间.
编辑:Sql Server查询我正在尝试运行
SELECT Transnum
FROM transactions
WHERE (txnnum = @Txnnum and txndatetime between @InitDate and @EndDate)
Run Code Online (Sandbox Code Playgroud)