C# 比较datetime和datepicker

C# 比较datetime和datepicker,c#,C#,嗨,你能帮帮我吗?第一个条件行,第二个不行。这是比较日期时间的正确方法吗?当我在meassageBox中写下这两个日期时间时,我可以看到它们是相等的,我不明白为什么它不起作用?从MSDN()返回0. DateTime date1=新的DateTime(2009,8,1,0,0,0); DateTime date2=新的日期时间(2009,8,1,12,0,0); int result=DateTime.Compare(date1,date2); 字符串关系; 如果(结果

嗨,你能帮帮我吗?第一个条件行,第二个不行。这是比较日期时间的正确方法吗?当我在meassageBox中写下这两个日期时间时,我可以看到它们是相等的,我不明白为什么它不起作用?从MSDN()返回0.

DateTime date1=新的DateTime(2009,8,1,0,0,0);
DateTime date2=新的日期时间(2009,8,1,12,0,0);
int result=DateTime.Compare(date1,date2);
字符串关系;
如果(结果<0)
relationship=“早于”;
否则如果(结果==0)
relationship=“与同时”;
其他的
relationship=“晚于”;
WriteLine({0}{1}{2}),date1,relationship,date2);
//该示例显示以下输出:
//2009年1月8日上午12:00:00早于2009年1月8日下午12:00:00

将它们作为日期时间而不是字符串进行比较
   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());
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