How do i make an action last a certain amount of time?

I'm using the hub-ee wheels to make a robot.
I want it to turn 90 degrees when it meets a wall.
To do that i need it to perform an action for an x amount of time.
So how do i make it do this (see code below) for 0.5 seconds?

   digitalWrite(leftIN1, HIGH);
    digitalWrite(leftIN2, LOW);
    analogWrite(leftPWM, 200);

    digitalWrite(rightIN1, HIGH);
    digitalWrite(rightIN2, LOW);
    analogWrite(rightPWM, 200);

Have you looked at the blink without delay example?
You should.

t0kmak:
To do that i need it to perform an action for an x amount of time.

If the current time - the start time >= x amount of time

You can stop doing the thing you're doing.