Page 1 of 1

time() subtraction

Posted: Sun Jul 25, 2004 6:34 pm
by Illusionist
Would this be the best way to determine if one date is 3 or more days older than today?

Code: Select all

$time = "1090492366";

echo date("n/j/y H:i:s",$time-date("Z"))."<br>";
echo date("n/j/y H:i:s",time()-date("Z"))."<br>";

$startTime= date("ynjHis",$time-date("Z"));
$today = date("ynjHis",time()-date("Z"));

if($today - $startTime>= 3000000){
	echo "over 3 days old";
}
The way the dates are inserted into the database is by the time() function, so this is the first thing I've put together and tested to check, but I was wondering if this would be sufficient or if there was something else I should do....

Posted: Sun Jul 25, 2004 7:01 pm
by feyd

Code: Select all

<?php

$time = "1090492366";
$now = time();

echo '$time (' . date('d M Y H:i:s',$time) . ') is ' . ((int)$time < ($now - 3 * 24 * 60 * 60) ? '' : 'not ') . 'older than 3 days from ' . date('d M Y H:i:s',$now);

?>

Posted: Sun Jul 25, 2004 8:29 pm
by ol4pr0

Code: Select all

#nice aswell. 
$now = time();
$later = strtotime('Thursday',$now);
$before = strtotime('3 days ago',$now);
print strftime("now: %c \n", $now);
print strftime("later: %c \n", $later);
print strftime("before: %c \n", $before);
feyd

Code: Select all

#whats this called ?! seen it a couple of times want to look into it a bit more.
? '' : 'not '

Posted: Sun Jul 25, 2004 9:03 pm
by feyd
The ternary.. : :arrow: look here

Posted: Sun Jul 25, 2004 9:05 pm
by Illusionist
Thanks feyd, that works alot better.