how do i replace delay with millis in this code

Anvay:
i am suin servotimer2 library.

Which would have been evident had you posted your entire sketch.

You’re producing new values for ‘iNewPos’, and ‘iOldPos’ on EVERY iteration of ‘loop()’. Is that what you really want?