### Time Calculations

Time calculations are needed when placing GAT (Good At Time) and GTD (Good Till Date) orders. The simplest way is to convert the TimeNum to a SecondNum, perform your calculations in Seconds, and then convert the SecondNum back to a TimeNum. The first two functions below will do that for you.

The next function applies a reference expressed in seconds to your Reference time. This reference would typically be used to Calculate GAT times. You may need this function when you want to apply an offset to a Time Reference and have orders activated automatically during the day without having to be online.

```function TimeNumToSecondNum( TimeNumber )
{
NumberSecs = int(3600*Hours+60*Minutes+Seconds);
return NumberSecs;```
```function SecondNumToTimeNum( SecondNum )
{
Hours = int(SecondNum /3600);
Minutes = int((SecondNum -Hours*3600)/60);
Seconds = int((SecondNum -Hours*3600)-Minutes*60);
TimeNumber = Hours*10000 + Minutes*100 + Seconds;
}```
```function ApplyOffsetToTimeNum( RefTimeNumber, Offset )
{
}```
```OffSet = Param("Offset in Seconds",0,-100,100,1);