Reputation: 2095
In my ASP.Net (VB Code) that I had 3 variable to store 3 different date.
how can I compare 3 variable to find the last day between 3 date ?
e.g.
date1 = '21/01/2011'
date2 = '31/12/2011'
date3 = '19/09/2011'
the result should be '31/12/2011' after comparsion
Thanks Joe
Upvotes: 1
Views: 1378
Reputation: 1613
This should work, with Linq library
Dim t1 As DateTime = DateTime.Parse("12/4/2011")
Dim t2 As DateTime = DateTime.Parse("12/2/2011")
Dim t3 As DateTime = DateTime.Parse("12/3/2011")
Dim dates As New List(Of DateTime)()
dates.Add(t1)
dates.Add(t2)
dates.Add(t3)
Dim latestdate As DateTime = dates.Max()
When you put it in a list you don't need worry if you have 3 dates or 300. This will always work.
Upvotes: 2
Reputation: 700342
You can just compare them:
Dim date1 As DateTime = #01/21/2011#
Dim date2 As DateTime = #12/31/2011#
Dim date3 As DateTime = #09/19/2011#
Dim last as DateTime = date1
If date2 > last Then
last = date2
End If
If date3 > last Then
last = date3
End If
Upvotes: 2