LOCAL ltTime AS Datetime m.ltTime = DATETIME() ? m.ltTime,NearestMinutes(m.ltTime,15) * Calculate nearest time, in minutes, for a given time FUNCTION NearestMinutes (ttTime AS Datetime, tnMinutes AS Integer) AS Datetime ASSERT TYPE("m.tnMinutes") = "N" AND BETWEEN(m.tnMinutes,1,30) ; MESSAGE "Minutes must be a number between 1 and 30" LOCAL lnMinutes AS Integer LOCAL lnTarget AS Integer * minutes part of time, in seconds m.lnMinutes = MINUTE(m.ttTime) * 60 + SEC(m.ttTime) * the fraction of an hour we are targeting m.lnTarget = INT(m.tnMinutes) * 60 LOCAL lnNearest AS Integer * find the nearest fraction, in seconds m.lnNearest = ROUND(m.lnMinutes / m.lnTarget,0) * m.lnTarget LOCAL ltNearest AS Datetime * add it to the zeroed initial time, and return it as a result m.ltNearest = (m.ttTime - m.lnMinutes) + m.lnNearest RETURN m.ltNearest ENDFUNC