tags:

views:

162

answers:

4

hi , i have the flowing code

$LastModified = filemtime($somefile) ;

i want to add ten minute to last modified time and compare with current time then if $LastModified+ 10 minute is equal to current time delete the file . how can i do that ?! i'm little confusing with unix time stamp .

+1  A: 

The unix timestamp is the number of seconds that have passed since Jan 1st, 1970.

Therefore to add 10 minutes you need to add 600 (seconds). To get the current time call time().

e.g.

$LastModified = filemtime($somefile);

if ($LastModified+600 <= time()
{
    // delete the file
}

(note that you said "if $LastModified+ 10 minute is equal to current time delete the file" - I presume you actually meant equal to or less than, otherwise replace <= with == above).

William
+2  A: 

Since the UNIX timestamp is expressed in "seconds since 1970", you just add five minutes in seconds:

$LastModPlusFiveMinutes = $lastModified + (60 * 5);

Or, maybe more readable:

$LastModPlusFiveMinutes = strtotime("+5 minutes", $lastModified);
deceze
A: 
$LastModified = filemetime($somefile);
$now = time();
if(strtotime($LastModified.'+10 minutes') >= $now){
    // delete the file.
}

That should do it.

inkedmn
i think you meant:if(strtotime($LastModified.'+10 minutes') >= $now)
Ahmet Kakıcı
gah, you're right - thanks! (fixed)
inkedmn
A: 

You wrote 5 minutes in the topic and 10 minutes in the context. Anyway here is the code

$diff =  time() - $LastModified ;
if( $diff >= 10 * 60 ){  // don't use ==, you may not find the right second..
    //action
}
Ahmet Kakıcı