Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Shared Function GetClosetDateToToday(lstOrderedDates As List(Of Date)) As Date
- ' Select the closest Delivery date to TODAY (inclusive) from the list of Ordered dates
- If lstOrderedDates.Count > 1 Then
- Dim dateToCheck = lstOrderedDates.ElementAt(1)
- Dim selectedDate = lstOrderedDates.ElementAt(0)
- For i = 1 To lstOrderedDates.Count - 1
- If dateToCheck < Date.Now.Date Then
- Exit For
- End If
- If dateToCheck >= Date.Now.Date Then
- selectedDate = dateToCheck
- End If
- If i + 1 < lstOrderedDates.Count Then
- dateToCheck = lstOrderedDates.ElementAt(i + 1)
- End If
- Next i
- Return selectedDate
- ElseIf lstOrderedDates.Count = 1 Then
- Return lstOrderedDates.First()
- End If
- Return Nothing
- End Function
- Public Shared Function GetClosetDateToToday(lstOrderedDates As List(Of Date)) As Date
- ' Select the closest Delivery date to TODAY (inclusive) from the list of Ordered dates
- If lstOrderedDates is Nothing OrElse lstOrderedDates.Count = 0 Then
- Return Nothing
- ElseIf lstOrderedDates.Count = 1
- Return lstOrderedDates.ElementAt(0)
- End If
- Dim ordered as List(Of DateTime) = lstOrderedDates.OrderByDescending(function(d) d).ToList()
- Dim selectedDate = ordered.ElementAt(0)
- For i = 1 To ordered.Count - 1
- Dim dateToCheck = ordered.ElementAt(i)
- If dateToCheck < Date.Now.Date Then
- Exit For
- End If
- selectedDate = dateToCheck
- Next i
- Return selectedDate
- End Function
- public static DateTime GetClosetDateToToday(List<DateTime> ordered)
- {
- if (ordered == null || ordered.Count == 0) { return default(DateTime); }
- var result = ordered
- .OrderByDescending(item => item)
- .LastOrDefault(item => item >= DateTime.Now);
- if (result == default(DateTime))
- {
- return ordered[0];
- }
- return result;
- }
- Public Shared Function GetClosetDateToToday(lstOrderedDates As List(Of Date)) As Date
- ' Select the closest Delivery date to TODAY (inclusive) from the list of Ordered dates
- If lstOrderedDates is Nothing OrElse lstOrderedDates.Count = 0 Then
- Return Nothing
- End If
- Dim found as DateTime = lstOrderedDates
- .OrderByDescending(function(d) d)
- .LastOrDefault(function(d) d >= DateTime.Now)
- If found is Nothing then
- found = lstOrderedDates.ElementAt(0)
- End If
- Return found
- End Function
Add Comment
Please, Sign In to add comment