Wednesday, August 24, 2016

How to compare Time only from the current date in C#

Following is the time comparison in 24 hour format

DateTime dt = DateTime.Parse(DateTime.Now.ToString ());

String strTime = dt.ToString("HH:mm");

if (strTime == System.Configuration.ConfigurationManager.AppSettings["ExecTime"].ToString())
{
// Matches
}

Or

if (strTime == “13:30”)
{
// Matches

}

No comments:

Post a Comment