Answered by:
Comparing time in vb.net

Question
-
User365103270 posted
Hi everyone, can i check with you, if i want to compare time... how can i do that... i have the following code
time_One = Now
el_Time = time_One - time_Two
Label1.Text = Now.ToShortTimeString
If Label1.Text < "06:30:00 PM" Then
Label1.Text = "-----"
Else
Label1.Text = el_Time.ToString
End IfI want to compare the current time with "06:30:00 PM"... so if the current time is smaller than "06:30:00 PM", i will do an action... how should i code?
Please assist me! Thanks!
Monday, June 9, 2014 2:10 AM
Answers
-
User-1716253493 posted
If DateTime.Parse(Label1.Text) < DateTime.Parse("06:30:00 PM") Then Label1.Text = "-----" Else Label1.Text = el_Time.ToString End If
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 9, 2014 3:19 AM
All replies
-
User-1618234021 posted
See the following:
http://stackoverflow.com/questions/2603182/how-can-i-compare-two-times-in-vb-net
http://msdn.microsoft.com/en-us/library/system.datetime.compare.aspx
Monday, June 9, 2014 2:24 AM -
User-821857111 posted
Dim now = DateTime.Now Dim date1 = New DateTime(now. Year, now.Month, now.Day, 18, 30, 0) If now < date1 Then 'it's before 18.30 End If
Monday, June 9, 2014 2:32 AM -
User1255597977 posted
sample code:
Dim time_1 As String = DateTime.Parse("06:30:00 PM").ToString("T") Dim time_2 As String = DateTime.Now.ToString("T") If DateTime.Compare(time_1, time_2) < 0 Then Response.Write(time_1.ToString() & " is < than " & time_2.ToString()) Else Response.Write(time_1.ToString() & " is > than " & time_2.ToString()) End If
Hope this will help u.
Monday, June 9, 2014 2:38 AM -
User-1716253493 posted
If DateTime.Parse(Label1.Text) < DateTime.Parse("06:30:00 PM") Then Label1.Text = "-----" Else Label1.Text = el_Time.ToString End If
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, June 9, 2014 3:19 AM -
User365103270 posted
hi thanks for the solution
Friday, June 13, 2014 5:30 AM