Hi hungth,
It looks like script that Vadim suggested is going to do what you want.
Error in your script is that you are using variable %T% outside of the FOR/NEXT loop where it's defined. You probably should have TIME = %T1% in REC statement, but Vadim's option is much more efficient and elegant.
Regards,
Gersh