2016-06-29 18 views
1
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を比較する正しい方法ですか?私はmeassageBoxでそのdatetimeの両方を書くとき、私は彼らが平等であることを見ることができ、なぜそれが動作しないのかわからないのですか?は、日付ピッカー

+1

文字列ではなく、文字列として比較してください。 – Jonesopolis

答えて

-1

より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 
+0

ty guys..solved .. – fvukovic