Hi, looking for a function that can add/subtract from TimeNum(). Tried using
dt = DateTimeConvert( 2, Null, 211700 );
newTime = DateTimeToStr( DateTimeAdd( dt, -90, in1Minute ), 0 );
without success. ‘newTime’ ends up equal to 1970-01-01 without a time portion. When using ‘2’ for the parameter, DateTimeToStr returns an empty string.
Below is my implementation for subtraction only. Any ideas/improvements would be great. Thanks
// set period in minutes
// get hour & minute components
period = 90; //Param( "Period in minutes:", 90, 1, 1440, 1 );
perHrs = period / 60;
perHrPt = int( perHrs );
perMnPt = period - ( perHrPt * 60 );
// set end time
endTime = "211700"; //ParamStr( "End time as string (hhmmss):", "1700" );
// handle subtraction that passes over midnight
// add 'endTime' hour to 240000 to
len = StrLen( endTime );
endHr = IIf( len == 6, StrToNum( StrLeft( endTime, 2 ) ),
IIf( len == 5, StrToNum( StrLeft( endTime, 1 ) ),
0 ));
endHr = 240000 + ( endHr * 10000 );
// get 'endTime' minute
endMn = IIf( len == 6, StrToNum( StrMid( endTime, 2, 2 ) ),
IIf( len == 5, StrToNum( StrMid( endTime, 1, 2 ) ),
IIf( len == 4, StrToNum( StrLeft( endTime, 2 ) ),
IIf( len == 3, StrToNum( StrLeft( endTime, 1 ) ),
0 ))));
// do subtraction
newHr = endHr - ( perHrPt * 10000 );
newMin = ( endMn - perMnPt );
// adjust if hour threshold is passed
if( newMin < 0 )
{
newHr = newHr - 10000;
newMin= 60 + newMin;
}
// finalize new time
newTime = newHr + ( newMin * 100 );
newTime = IIf( newTime >= 240000, newTime - 240000, newTime );