Alright so whatever i do i cant get this to work.
Now...im not a wizzard or anything but why does it have to be so damn hard to find out if its more than 2 minutes or more in difference by the time in database to now.
The "timed" in database is a `datetime` and looks like this "2011-06-16 14:55:33"
anyone got any solutions?
require_once "db_connect.inc.php";
$thisplace = "delinquency";
$sql = "SELECT timed FROM g_timer WHERE place='$thisplace' AND user='$username' LIMIT 1";
$result = mysql_query($sql);
if($result) {
$row = mysql_fetch_assoc($result);
$timed = $row['timed'];
$date = $timed;
if(empty($date)) {
return "No date provided";
}
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$unix_date = strtotime($date);
// check validity of date
if(empty($unix_date)) {
return "Bad date";
}
// is it future date or past date
if($now > $unix_date) {
$difference = $now - $unix_date;
$tense = "ago";
} else {
$difference = $unix_date - $now;
$tense = "from now";
}
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if($difference != 1) {
$periods[$j].= "s";
}
return "$difference $periods[$j] {$tense}";
//$timer = nicetime($date); // 2 days ago
//echo $timer;
if($periods[$j] =="minutes" or "hours" or "days" or "weeks" or"months" or "years" and $tense == "ago"){
///Let the user do what he wants
}else echo "You have to wait";
}else echo "No data found in the database";