I am looping through a list of DateTime variables and have got the .ToUniversalTime variable. I want to find out from the list which is the closest one approaching Now.ToUniversalTime but am having difficulty trying to work it out

I had it looping through like this but this isn't much good as I only want to return the one that is the closest approaching to the system time.

If TodaysCard(i).eventDate.ToUniversalTime < Now.ToUniversalTime Then

Any guidance would be greatly appreciated.
Thanks,

I am looping through a list of DateTime variables and have got the .ToUniversalTime variable. I want to find out from the list which is the closest one approaching Now.ToUniversalTime but am having difficulty trying to work it out

I had it looping through like this but this isn't much good as I only want to return the one that is the closest approaching to the system time.

If TodaysCard(i).eventDate.ToUniversalTime < Now.ToUniversalTime Then

Any guidance would be greatly appreciated.
Thanks,

Hi,

Try this:

Dim tempUTC as Date = CDate("01/01/2010")
tempUTC = tempUTC.ToUniversalTime
'Add your loop code here...
If TodaysCard(i).eventDate.ToUniversalTime < Now.ToUniversalTime Then
If TodaysCard(i).eventDate.ToUniversalTime > tempUTC Then tempUTC = TodaysCard(i).eventDate.ToUniversalDate
Else
'Exit Loop
End If
'Return tempUTC

You may or may not want to jump out of the loop depending on whether your list is sorted of course (and I'm not sure how you're looping through the list either - so it's not in the example, sorry).

Something along these lines should do what you want though.

Chris.

That looks great Chris.
Thank you.

:)

Edited 6 Years Ago by jackiejoe: n/a

This article has been dead for over six months. Start a new discussion instead.