Reputation: 25
How do I code Time greater than 8:15
?
I want to to have a button with a condition that if the time greater than 8:15
it will not be visible.
Upvotes: 1
Views: 145
Reputation: 29026
Let inputTime
be the input time that you have, then you can use the following code for comparison:
DateTime inputTime = DateTime.Now; // initializing with current DateTime
bool isGreater = inputTime.TimeOfDay > new TimeSpan(8,15,0);
if(isGreater)
{
// code here time is Greater
}
Here the TimeOfDay
property will give you the current time(is of type TimeSpan
), it is directly comparable with another TimeSpan
object, so we can make use of the Constructor of the TimeSpan
class to create a Timespan equivalent to 8:15
. Now the variable isGreater
will have the comparison result. Take a Look at this example
Upvotes: 7