any 1 wit php time different function .i.e 1sec ago. yesterday.
php time ago
Collapse
X
-
PHP Code:function gettimemsg($sec)
{
$years = 0;
$months = 0;
$weeks = 0;
$days = 0;
$mins = 0;
$hours = 0;
if($sec>59)
{
$secs = $sec%60;
$mins = $sec/60;
$mins = (integer)$mins;
}
if($mins>59)
{
$hours = $mins/60;
$hours = (integer)$hours;
$mins = $mins%60;
}
if($hours>23)
{
$days = $hours/24;
$days = (integer)$days;
$hours = $hours%24;
}
if($days>6)
{
$weeks = $days/7;
$weeks = (integer)$weeks;
$days = $days%7;
}
if($weeks>3)
{
$months = $weeks/4;
$months = (integer)$months;
$weeks = $weeks%4;
}
if($months>11)
{
$years = $months/12;
$years = (integer)$years;
$months = $months%12;
}
if($years>0)
{
if($years==1)
{
$yearmsg = "year";
}else{
$yearmsg = "years";
}
if($months==1)
{
$monthsmsg = "month";
}else{
$monthsmsg = "months";
}
if($days==1)
{
$daysmsg = "day";
}else{
$daysmsg = "days";
}
if($hours==1)
{
$hoursmsg = "hour";
}else{
$hoursmsg = "hours";
}
if($mins==1)
{
$minsmsg = "minute";
}else{
$minsmsg = "minutes";
}
if($secs==1)
{
$secsmsg = "second";
}else{
$secsmsg = "seconds";
}
if($months!=0)
{
$monthscheck = "$months $monthsmsg ";
}else{
$monthscheck = "";
}
if($days!=0)
{
$dayscheck = "$days $daysmsg ";
}else{
$dayscheck = "";
}
if($hours!=0)
{
$hourscheck = "$hours $hoursmsg ";
}else{
$hourscheck = "";
}
if($minutes!=0)
{
$minscheck = "$mins $minsmsg ";
}else{
$minscheck = "";
}
if($secs!=0)
{
$secscheck = "$secs $secsmsg";
}else{
$secscheck="";
}
return "$years $yearmsg $monthscheck$dayscheck$hourscheck$minscheck$secscheck";
}
if(($years<1) && ($months>0))
{
if($months==1)
{
$monthsmsg = "month";
}else{
$monthsmsg = "months";
}
if($days==1)
{
$daysmsg = "day";
}else{
$daysmsg = "days";
}
if($hours==1)
{
$hoursmsg = "hour";
}else{
$hoursmsg = "hours";
}
if($mins==1)
{
$minsmsg = "minute";
}else{
$minsmsg = "minutes";
}
if($secs==1)
{
$secsmsg = "second";
}else{
$secsmsg = "seconds";
}
if($days!=0)
{
$dayscheck = "$days $daysmsg ";
}else{
$dayscheck = "";
}
if($hours!=0)
{
$hourscheck="$hours $hoursmsg ";
}else{
$hourscheck = "";
}
if($minutes!=0)
{
$minscheck = "$mins $minsmsg ";
}else{
$minscheck = "";
}
if($secs!=0)
{
$secscheck = "$secs $secsmsg";
}else{
$secscheck = "";
}
return "$months $monthsmsg $dayscheck$hourscheck$minscheck$secscheck";
}
if(($months<1) && ($weeks>0))
{
if($weeks==1)
{
$weeksmsg = "week";
}else{
$weeksmsg = "weeks";
}
if($days==1)
{
$daysmsg = "day";
}else{
$daysmsg = "days";
}
if($hours==1)
{
$hoursmsg = "hour";
}else{
$hoursmsg = "hours";
}
if($mins==1)
{
$minsmsg = "minute";
}else{
$minsmsg = "minutes";
}
if($secs==1)
{
$secsmsg = "second";
}else{
$secsmsg = "seconds";
}
if($days!=0)
{
$dayscheck = "$days $daysmsg ";
}else{
$dayscheck = "";
}
if($hours!=0)
{
$hourscheck = "$hours $hoursmsg ";
}else{
$hourscheck = "";
}
if($minutes!=0)
{
$minscheck = "$mins $minsmsg ";
}else{
$minscheck = "";
}
if($secs!=0)
{
$secscheck = "$secs $secsmsg";
}else{
$secscheck = "";
}
return "$weeks $weeksmsg $dayscheck$hourscheck$minscheck$secscheck";
}
if(($weeks<1) && ($days>0))
{
if($days==1)
{
$daysmsg = "day";
}else{
$daysmsg = "days";
}
if($hours==1)
{
$hoursmsg = "hour";
}else{
$hoursmsg = "hours";
}
if($mins==1)
{
$minsmsg = "minute";
}else{
$minsmsg = "minutes";
}
if($secs==1)
{
$secsmsg = "second";
}else{
$secsmsg = "seconds";
}
if($hours!=0)
{
$hourscheck = "$hours $hoursmsg ";
}else{
$hourscheck = "";
}
if($minutes!=0)
{
$minscheck = "$mins $minsmsg ";
}else{
$minscheck = "";
}
if($secs!=0)
{
$secscheck = "$secs $secsmsg";
}else{
$secscheck = "";
}
return "$days $daysmsg $hourscheck$minscheck$secscheck";
}
if(($days<1)&&($hours>0))
{
if($hours==1)
{
$hoursmsg = "hour";
}else{
$hoursmsg = "hours";
}
if($mins==1)
{
$minsmsg = "minute";
}else{
$minsmsg = "minutes";
}
if($secs==1)
{
$secsmsg = "second";
}else{
$secsmsg = "seconds";
}
if($minutes!=0)
{
$minscheck = "$mins $minsmsg ";
}else{
$minscheck = "";
}
if($secs!=0)
{
$secscheck = "$secs $secsmsg";
}else{
$secscheck = "";
}
return "$hours $hoursmsg $minscheck$secscheck";
}
if(($hours<1) && ($mins>0))
{
if($mins==1)
{
$minsmsg = "minute";
}else{
$minsmsg = "minutes";
}
if($secs==1)
{
$secsmsg = "second";
}else{
$secsmsg = "seconds";
}
if($secs!=0)
{
$secscheck = "$secs $secsmsg";
}else{
$secscheck = "";
}
return "$mins $minsmsg $secscheck";
}
if(($mins<1) && ($sec>0))
{
if($sec==1)
{
$secsmsg = "second";
}else{
$secsmsg = "seconds";
}
if($sec!=0)
{
$secscheck = "$sec $secsmsg";
}else{
$secscheck = "";
}
return "$secscheck";
}
$yr = floor($sec/60/60/24/365);
if($yr>0)
{
if($yr==1)
{
return "$yr year";
}else{
return "$yr years";
}
}
$mnth = floor($sec/60/60/24/7/4);
if($mnth>0)
{
if($mnth==1)
{
return "$mnth month";
}else{
return "$mnth months";
}
}
$wks = floor($sec/60/60/24/7);
if($wks>0)
{
if($wks==1)
{
return "$wks week";
}else{
return "$wks weeks";
}
}
$ds = floor($sec/60/60/24);
if($ds>0)
{
if($ds==1)
{
return "$ds day";
}else{
return "$ds days";
}
}
$hs = floor($sec/60/60);
if($hs>0)
{
if($hs==1)
{
return "$hs hour";
}else{
return "$hs hours";
}
}
$ms = floor($sec/60);
if($ms>0)
{
if($ms==1)
{
return "$ms minute";
}else{
return "$ms minutes";
}
}
return "$sec seconds";
}
PHP Code:$tm = mysql_fetch_array(mysql_query("SELECT time_posted FROM wall_table WHERE wall_id='my_wall_id'"));
$var1 = date("g:i:s a",$tm[0]);
$var2 = time();
$var21 = date("g:i:s a");
$var3 = $var21 - $var1;
$var4 = date("s",$var3);
$remain = time() - $tm[0];
$msg = gettimemsg($remain);
echo "User posted something on your wall $msg ago.";
Last edited by metulj; 04.07.10, 07:29.My Blog: http://jhommark.blogspot.com
My Facebook: http://www.facebook.com/jhommark
My Official Site: http://www.undergroundweb.tk
My Community Site: http://undergroundwap.xtreemhost.com
Comment
Comment