What compiler are you using? By quick test it seems you need to declare everything as longint, or type convert them when using with variable t.

By quick test with Lazarus i can get that happen only if i do this:
aux, aux1, aux2, s, m, h, d : smallint;

So with your compiler, integer = smallint which doesn't understand values over 32767.