1 Attachment(s)
help with DateTime.Compare
hi! can anybody please help me. Why is it when i try to compare two the same dates I was not getting the right return value of Datetime.Compare which 0. I dont know if the problem is in my code or is in the Datetime.Compare method. by the way, i attched a screenshot to give you more idea. Thanks in advance!
Re: help with DateTime.Compare
Actually, that's my fault. I gave you a bum steer with using AddSeconds like that. That will zero the seconds but in your case the two times will still have different numbers of milliseconds. I think you'll have to create a new DateTime object using the constructor instead:
Code:
DateNow = New DateTime(DateNow.Year, DateNow.Month, DateNow.Day, DateNow.Hour, DateNow.Minute, 0);
Re: help with DateTime.Compare
i got an error when try that why is it?
Code:
DateTime EvntDate = new DateTime(EvntDate.Year, EvntDate.Month, EvntDate.Day, EvntDate.Hour, EvntDate.Minute, 0);
DateTime AlarmDate = new DateTime(AlarmDate.Year, AlarmDate.Month, AlarmDate.Day, AlarmDate.Hour, AlarmDate.Minute, 0);
DateTime DateNow = new DateTime(DateNow.Year, DateNow.Month, DateNow.Day, DateNow.Hour, DateNow.Minute, 0);
Error detail:
Quote:
Error 1 Use of unassigned local variable 'EvntDate' C:\Documents and Settings\daimous\My Documents\Visual Studio 2005\Projects\BCMD\WindowsApplication1\frmindex.cs 830 50 RefNumGen
Re: help with DateTime.Compare
Yeah. The DateTime variable has to already contain a DateTime value for you to use it on the right-hand side of an assignment. The code you posted previously was:
Code:
DateNow = DateTime.Now;
DateNow = DateNow.AddSeconds(-DateNow.Second);
The code that I posted was supposed replace the SECOND line of that.
Also, those three "new DateTime()" calls are unnecessary. Just declare the variables and assign the initial values on one line, THEN remove the seconds on the NEXT line, e.g.
Code:
DateTime evntDate = DateTime.Parse(...);
evntDate = New DateTime(eventDate.Year, ...);
Re: help with DateTime.Compare