Arduino controlled relay for certain duration of time
you need to update the timeElapsed variable inside the while loop:

 unsigned int interval = ftime*1000; //ftime in ms
 unsigned long startTime = millis();
do
  {
      digitalWrite(Relay1, LOW);
      timeElapsed = millis() - startTime;
  }
  while(timeElapsed &lt; interval);
digitalWrite(Relay1, HIGH);


Another way is to create a state machine make startTime a global and update the logical state (and the pin) when the time is elapsed. 

unsigned long startTime;
bool relayLOW = false;

void loop(){

    if(relayLOW &amp;&amp; millis() - startTime &gt; interval){
        digitalWrite(Relay1, HIGH);
        relayLOW = false;
    }
    if(!relayLOW){
        bool closeRelay= //decide if relay needs to be triggered
        if(closeRelay){
            startTime = millis();
            digitalWrite(Relay1, LOW);
            relayLOW = true;
        }
    }
}