westman Posted July 29, 2012 Share Posted July 29, 2012 hi all,i got 1 for you i am placing this in my DB...$time = time() - 259200;witch is (now - 3 days) and i am using VAR (50) in my DB how can i pull this out on my DB to show on the page... "2days,7hours,34min left" i looked at...http://www.w3schools.com/php/func_date_time.aspbut it only shows days and i need time any help? Link to comment Share on other sites More sharing options...
niche Posted July 30, 2012 Share Posted July 30, 2012 This should help http://stackoverflow.com/questions/3707506/convert-unix-timestamp-php Link to comment Share on other sites More sharing options...
justsomeguy Posted July 30, 2012 Share Posted July 30, 2012 It's just basic math. You divide by 86400 to get the days. You divide the remainder by 3600 to get the number of hours. Divide the remainder by 60 to get the number of minutes, etc. Link to comment Share on other sites More sharing options...
westman Posted July 31, 2012 Author Share Posted July 31, 2012 got it!!!... i 1st tryed... function time_elapsed_A($secs){ $bit = array( 'y' => $secs / 31556926 % 12, 'w' => $secs / 604800 % 52, 'd' => $secs / 86400 % 7, 'h' => $secs / 3600 % 24, 'm' => $secs / 60 % 60, //'s' => $secs % 60 ); foreach($bit as $k => $v) if($v > 0)$ret[] = $v . $k; return join(' ', $ret); }$nowtime = time();$dis_time_left = time_elapsed_A($dis_d_time_indb - $nowtime)."\n"; and i found a bug in this so i made... $nowtime = time();$secs = ($dis_d_time_indb - $nowtime);$day_left = $secs / 86400 % 7;$hour_left = $secs / 3600 % 24;$min_left = $secs / 60 % 60;$dis_time_left = '' . $day_left .' D ' . $hour_left . ' H ' . $min_left . ' M ''; and this works for me 100% of the time thank you and please comment Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now