Time comparison with filecttime not evaulating right.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

akimm wrote:Did I over complicate?
yes

Code: Select all

<?php
$threshold = time() - (86400 * 10);

foreach ( glob('*.*') as $filepath ) {
	$created = filectime($filepath);
	
	if ($created > $threshold) {
		echo '*new* ';
	}
	echo $filepath, ' - ', date('Y-m-d H:i:s', $created), "<br />\n";
}
?>
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

Thanks Feyd, i'll see about changing that.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

Volka, why do you want the interger 864k minus this time?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

That's the calculation for ten days ago.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

so its all in seconds, ok.. I was thinking that I was just not sure. Thanks for clarification.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

$threshold = strtotime('now - 10 days');
// or
$threshold = strtotime('today - 10 days');
might be more intuitive.
And yes, unix timestamps are in seconds (since start of epoche).
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

Volka, I have tried your solution, and many others by experimenting with different variables, and implementing different ones. It always has the same result, it prints all the files, its like it ignores the time comparrison.

Code: Select all

<?php
error_reporting (E_ALL);
$img = "<img src=http://www.akimm.com/images/new1.gif>";
$threshold = strtotime('today - 10 days');
$path = "article/";
foreach(glob($path . "/*.txt") as $file) {
        $created = filectime($file);
        $file = basename($file);
        $compare = ($created - $threshold);
        if ($compare <= 10) {
                echo "<ul>" . "<li>" . $img .  $file . "<a href=http://www.akimm.com/philosophy.php>" .  "   Click to view " . "</a>" . "</li>" . "</ul>";
												#break;
        } else {
echo "<br />" . "<br />" . "no new articles, add one by" . "<a href=http://www.akimm.com/add_art.php>" . "  clicking here " . "</a>";
												break;
				}
			}
?>
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

If you are wondering, I added basename, cuz everytime it printed the $file it printed a leading article/ before it, which messed up my CSS a bit, so I stripped that with basename, as for the addition of variables, I did that because nothing else was working. This still doesn't do the trick.

I even recently tried this,

Code: Select all

$today = strtotime('today');
foreach(glob($path . "/*.txt") as $file) {
        $created = filectime($file);
        $file = basename($file);
        $compare = ($created - $threshold);
        if ($compare <= $today)
Still no luck.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

What's the output of

Code: Select all

<?php
$threshold = time() - (86400 * 10);

foreach ( glob('article/*.txt') as $filepath ) {
	$created = filectime($filepath);
	if ($created > $threshold) {
		echo '*new* ';
	}
	echo $filepath, ' - ', date('Y-m-d H:i:s', $created), "<br />\n";
}
?>
without any changes?
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

"article/Foley\'s Adventure1.txt - 2006-10-05 13:12:37
article/Sleepless, i step into insanity.2.txt - 2006-10-06 01:41:39
*new* article/s6.txt - 2006-10-28 11:47:13"

Only the bottom one is actually new.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

akimm wrote:"article/Foley\'s Adventure1.txt - 2006-10-05 13:12:37
article/Sleepless, i step into insanity.2.txt - 2006-10-06 01:41:39
*new* article/s6.txt - 2006-10-28 11:47:13"

Only the bottom one is actually new.
And only the last entry is marked as *new* => the actual comparison is working.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

Yea, but it prints all, the way the program is written I thought it would print only the new files. Believe it or not, I had this working some time ago, then I tried to add some functionallity to it, and messed it all up.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Don't know what you did.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

yea me either, I will keep trying, I'll post some codes, up later, maybe someone will notice something wrong after I do some BIO hw on work on this some more..

See ya, thanks for the help you've given.
Post Reply