How to Compare time

Platform: ASP.NET| Category: Basic

VB.NET


Dim t1 As String = DateTime.Parse('3:30 PM').ToString('t')
Dim t2 As String = DateTime.Now.ToString('t')
If DateTime.Compare(DateTime.Parse(t1), DateTime.Parse(t2)) < 0 Then
	Response.Write(t1.ToString() & ' is < than ' & t2.ToString())
Else
	Response.Write(t1.ToString() & ' is > than ' & t2.ToString())
End If

C#


string  t1    = DateTime.Parse('3:30 PM').ToString('t');
string t2  = DateTime.Now.ToString('t');
if (DateTime.Compare(DateTime.Parse (t1), DateTime.Parse (t2)) < 0 )
{
	Response.Write(t1.ToString() + ' is < than ' + t2.ToString());
}
else
{
	Response.Write(t1.ToString() + ' is > than ' + t2.ToString());
}

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.