# Optimize over time intervals shorter than an hour

I’ve got coder’s block and would appreciate a nudge in the right direction.

Currently I optimize time by using Timenum() in the following way:

``````// Do the time optimization
startTime = Optimize("startTime", 40000, 0, 150000, 10000);  // HHMMSS format
endTime = 160000;  // end in HHMMSS format
timeOK = tn >= startTime AND tn <= endTime;
``````

It works fine for hourly intervals but I would like to use a 15 minute interval. Just adding 1500 does not work because after 45 minutes every thing goes south (46000 and 47500 are not in the HHMMSS format anymore).

Something I’ve tried was using a custom array as per the example by Herman van den Bergen in the Optimize comments, but that does not feel like the correct solution.

What is the base unit if doing time calculations?
Have you not learned in school to better use seconds?
I have learned it in elementary school.

To create TimeToSeconds and SecondsToTime functions is your homework.
Basic math.

``````// Create functions TimeToSeconds and SecondsToTime

default = TimeToSeconds( 40000 );
_min = 0;//TimeToSeconds( 40000 );
_max = TimetoSeconds( 150000 );
_step = Interval();

optsec = Optimize ("SecondNum", default, _min, _max, _step );
starttime = SecondsToTime( optsec );

_TRACEF( "sec: %g, tn: %g", optsec, starttime );

endTime = 160000;  // end in HHMMSS format
timeOK = tn >= startTime AND tn <= endTime;
``````
1 Like

The simplest method is just adding second Optimize statement just for minutes

``````// Do the time optimization