Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding time matches

Status
Not open for further replies.

NIWANut

Programmer
May 20, 2003
25
NZ
Hi,

I have two excel data files that have a DateTime column in the following format

dd/mm/yyyy hh:mm:ss

What I want to do is take the first DateTime value in file one and find the closest time in file two and then copy some data from file two to file one. All the copying etc is no problem, my mental block is how to find the closest time.

Some explanation. The DateTime fields are from two separate instruments. In file one each DateTime is approximately 3 minutes apart and they could have any number of seconds e.g.
10/10/2000 14:12:22

File two is from a data logging system that should log on the even minute, it doesn't. It can be up to 1 second out either way so we get
10/10/2000 14:11:59 or
10/10/2000 14:12:00 or
10/10/2000 14:12:01

I have written a simple routine to take the DateTime from the file one and produce a DateTime with even seconds to the closest minute, so for the example given above where the seconds are 22 the corrected DateTime is 10/10/2000 14:12:00, if the seconds were 30 or greater it would have been 10/10/2000 14:13:00. Now I can do my comparison but because the time in file two can be out by 1 second the comparison may fail. I could do three comparisons but that seems ugly, could also convert the DateTime in file two to be an equal minute but I was hoping for a simpler solution.

If you can understand this, any ideas.

George
 
If you sort the data in file2, you could use a vlookup with the 4th argument set to true - this will look for the nearest match that is below or equal to the value in file 1....

Rgds, Geoff
Quantum materiae materietur marmota monax si marmota monax materiam possit materiari?
Want the best answers to your questions ? faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top