比较日期时间和日期拾取器
本文关键字:日期 时间 比较 | 更新日期: 2023-09-27 17:53:02
var upit = (from c in baza.Dnevnik_rada
where c.ID_smjena.ToString()==cmbOdabirSmjene.Text
&& c.Datum.ToString()==(dtpOdabirDatuma.Text +" 0:00:00" )
select c.ID_radnik);
MessageBox.Show(upit.FirstOrDefault().ToString());
嗨,你能帮我吗,第一个条件有效,但第二个条件不行。这是比较日期时间的正确方法吗?当我在messagebox中写这两个日期时间时,我可以看到它们是相等的,我不明白为什么它不起作用?返回0。
From MSDN(https://msdn.microsoft.com/en-us/library/).
DateTime date1 = new DateTime(2009, 8, 1, 0, 0, 0);
DateTime date2 = new DateTime(2009, 8, 1, 12, 0, 0);
int result = DateTime.Compare(date1, date2);
string relationship;
if (result < 0)
relationship = "is earlier than";
else if (result == 0)
relationship = "is the same time as";
else
relationship = "is later than";
Console.WriteLine("{0} {1} {2}", date1, relationship, date2);
// The example displays the following output:
// 8/1/2009 12:00:00 AM is earlier than 8/1/2009 12:00:00 PM