Keep RTC time in a loop
Check '{' and '}' pairs in your code.

void loop(){
    long duration, distance;
    digitalWrite(trigPin, LOW);  
    delayMicroseconds(2); 
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10); 
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration/2) / 29.1;
    if (distance &lt;= 4) { 
        inTime= rtc.getTimeStr();
        Serial.println(inTime);

   } 
} //&lt;--- what is this little fella doing here?
    else if (distance &gt;= 5 || distance &lt;= 0){
    Serial.println("Out of range");
    }

delay(500);
}