I'm working on a code which has a logic but I'm unable to compare to them using if can any one please help.
This I have a logic I global.aspx
string sTime = System.Configuration.ConfigurationManager.AppSettings["StartTime"].ToString();
string eTime = System.Configuration.ConfigurationManager.AppSettings["EndTime"].ToString();
DateTime s = DateTime.Parse(sTime);//here i'm getting an Exception while debugging
DateTime e = DateTime.Parse(eTime);
DateTime nTime = DateTime.Now;
if (nTime >= s || nTime < s)
{
InvokeUnderMaintenance();
}
Exception
System.FormatException was unhandled by user code
HResult=-2146233033 Message=String was not recognized as a valid DateTime. Source=mscorlib StackTrace: at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.DateTime.Parse(String s) at EsiTrak.Web.MvcApplication.Application_PostAuthenticateRequest() in C:\Project\EsitrakWebEnablement\EsiTrak.Web\Global.asax.cs:line 138
InnerException:message::An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code
This I have taken in webconfig file as time starttime and end time values
<add key="StartTime" value="12"/>
<add key="EndTime" value="18"/>
Can any one tell me how to comapre start time and end time with current time using ||
operator or &&
operator?