I am writing some data analysis software, I want to upscale timebase of my Raw Data. My Raw Data has a time step of ~2minutes. I want to scale the data into several database tables with a timestep of 5minutes, hourly, daily and monthly. I plan to run each of these from the raw data to keep my accuracy up.
The problem I am currently having is taking an initial value and finding the closest ’round’ time point I want to it, to be my start point. For example, I will start with the point 13/03/12 00:01:36 as my start point, I want the code to find 13/03/12 00:00:00 as the closest time point so it will start calculating from there. For each time point I want to take half of the time step on each side. So 12/03/12 23:57:30 to 13/03/12 00:02:29 will become 13/03/12 00:00:00.
The Data is taken from Access using a SQL query and the Date and Value are stored in two side by side Arrays. Below is my code so far. It will round the values up to the NEXT 5 minutes, rather than up or down to the NEAREST 5 mimutes.
Private Sub RateStateScale(ByVal Parameter As Integer, ByVal Timebase As String)
Dim NewDate(0)
Dim NewData(0)
Dim RecordCounter
Dim MinValue As Date = ScaleDate(0)
Dim startpoint As String
For RecordCounter = 0 To ScaleDate.GetLength(0)
If MinValue > ScaleDate(RecordCounter) Then
MinValue = ScaleDate(RecordCounter)
End If
Next
Do Until MinValue.Minute Mod 5 = 0
MinValue = MinValue.AddMinutes(1)
Loop
End Sub
Thanks for your help
Let’s try some VB, for a “round to nearest 5 minutes” function: