time variable?

basically i have a bit of code that states the LED will be on when the RFID tag is within range, but i need a piece of code that states that if it is out of range for 1/2 seconds it will turn off?

At the moment then the LED flashes off every time the rfid module refreshes the scan so i want it to wait for roughly 1/2 seconds before it turns off?

i need it between the while and if command:

while(rfid.available()>0){
    c=rfid.read(); 
    msg += c;
    Serial.println(msg);  
    Serial.println(msg.length());
    digitalWrite(8,HIGH);
  }
  if(rfid.available()==0){
    c=rfid.read();
    digitalWrite(8,LOW);  
  }

This is the entire code if that makes it any easier for people?

#include <SoftwareSerial.h>

#define ADD_TAG_CODE "0001361049"  //change this ID with your own card TAG
#define DEL_TAG_CODE "0000946210"  //change this ID with your own card TAG

SoftwareSerial rfid = SoftwareSerial(5,6);
String msg;
String ID ;  //string to store allowed cards

void setup()  
{
  Serial.begin(9600);
  Serial.println("Serial Ready");

  rfid.begin(9600);
  Serial.println("RFID Ready");
  
  pinMode(8,OUTPUT);
}

char c;

void loop(){

digitalWrite(5,LOW);
digitalWrite(6,LOW);

delay(1);

digitalWrite(5,HIGH);
digitalWrite(6,HIGH);

if(Serial.available())
{
while(Serial.available())
Serial.write(Serial.read());
}
  while(rfid.available()>0){
    c=rfid.read(); 
    msg += c;
    Serial.println(msg);  
    Serial.println(msg.length());
    digitalWrite(8,HIGH);
  }
  if(rfid.available()==0){
    c=rfid.read();
    digitalWrite(8,LOW);  
  }  
}

Try this (untested).

while(rfid.available()>0){
    c=rfid.read(); 
    msg += c;
    Serial.println(msg);  
    Serial.println(msg.length());
    digitalWrite(8,HIGH);
    ledOnTime = millis();  // record when led turned on
  }
  if(rfid.available()==0 && (millis() - ledOnTime >= 500) ){  // check for no data and 0.5 seconds elapsed
    c=rfid.read();                                                        // why read if nothing is there?
    digitalWrite(8,LOW);  
  }

Pins default to input. Here all you are doing is turning the internal pullup resistors off and on.

digitalWrite(5,LOW);
digitalWrite(6,LOW);

delay(1);

digitalWrite(5,HIGH);
digitalWrite(6,HIGH);