Hi Friends,
I want to compare the system time with 11.00 AM on a button click event. And if the current time is greater than or equal to 11.00 AM, i've to perform some functions.
Compares two instances of DateTime and returns an integer that indicates whether the first instance is earlier than, the same as, or later than the second instance.
C# Code
private void button1_Click(object sender, EventArgs e)
{
DateTime systemDate = DateTime.Now;DateTime compareDate = Convert.ToDateTime("11:00AM");
// less thanif (compareDate < systemDate)
Console.WriteLine("It's past 11 AM");// equal toif (compareDate == systemDate)Console.WriteLine("It's the same time as");// greater thanif (compareDate > systemDate)Console.WriteLine("It's not 11 AM yet");
}
Comments
Post a Comment