defroster Posted December 11, 2011 Share Posted December 11, 2011 Hello, When I use this function, the time always refers to January 1st 1970 ?! How come? I get the output '4 decades 1 year 11 months' regardless of which date I enter into the function.. ? function timeAgo($tm,$rcs = 2) { $cur_tm = time(); $dif = $cur_tm-$tm; $pds = array('second','minute','hour','day','week','month','year','decade'); $lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600); for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]); $no = floor($no); if($no <> 1) $pds[$v] .='s'; $x=sprintf("%d %s ",$no,$pds[$v]); if(($rcs > 0)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= timeAgo($_tm, --$rcs); return $x; } When I call for the function I use this: timeAgo($row['dateposted']) The format in the database for 'dateposted' is: 2006-08-14 23:29:23 Any ideas what I am doing wrong? Thanks a million Quote Link to comment https://forums.phpfreaks.com/topic/252940-time-ago-function-always-referring-to-january-1st-1970/ Share on other sites More sharing options...
kicken Posted December 11, 2011 Share Posted December 11, 2011 The function appears to be expecting a unix timestamp value, but your providing it something else. You need to convert the value from your database into a timestamp prior to passing it to the function. strtotime will probably work. Quote Link to comment https://forums.phpfreaks.com/topic/252940-time-ago-function-always-referring-to-january-1st-1970/#findComment-1296827 Share on other sites More sharing options...
defroster Posted December 11, 2011 Author Share Posted December 11, 2011 Thanks. This did it. timeAgo(strtotime($row['dateposted'])) Quote Link to comment https://forums.phpfreaks.com/topic/252940-time-ago-function-always-referring-to-january-1st-1970/#findComment-1296840 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.