-
algorithm help
I am just not the usual me today and it sucks!!! :(
I need some help.
We have an object. it has a datetime property.
What I want to do is to execute a certain condition IF TRUE.
condition:
if the object datetime hour == current hour (but should fail if the minute given as input is < current minute) or the hour given is > current hour and minute input can be of any value as long as the hour given is > current hour.
does that makes sense? lol
how can I make that into a conditional IF statement? :)
-
Re: algorithm help
actually I think I got it after re-reading this thread LOL
but still I would like your suggestions!
-
Re: algorithm help
Correct me if I'm wrong but basically you want to test whether the time portion of a DateTime object is later than the current time of day, yes? If so you can use the fact that TimeSpan objects support the standard comparison operators.
Code:
TimeSpan inputTime = inputDate.TimeOfDay;
TimeSpan currentTime = DateTime.Now.TimeOfDay;
if (inputTime > currentTime)
MessageBox.Show("The selected time is after the current time.");
else if (inputTime < currentTime)
MessageBox.Show("The selected time is before the current time.");
else
MessageBox.Show("The selected time is the current time.");
-
Re: algorithm help
well that is partially correct but I want to make sure that it does not "clash" with another time object but I have it sorted now :)