Help with timedifference function
03-08-10, 05:53 PM
Newbie Coder
Join Date: Jan 2010
Posts: 27
Thanks: 5
Thanked 0 Times in 0 Posts
Help with timedifference function
Hi its me again....
I'm trying to adapt the timediffrence function by JCBones
here in a new program of mine..the code previously shows only hours and not days..right now i also want to show day if it after 24 hour..
like 1 day ago...2 days ago etc
right now my new code is working except it still show hours if if excedeed 24 hours....example
http://img695.imageshack.us/img695/2149/41633294.jpg
this must be simple..but i can't figure this out...help a noob
p/s: sorry for my english
Last edited by sarahmx; 03-08-10 at 06:02 PM .
03-08-10, 07:36 PM
Aspiring Coder
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
03-08-10, 11:37 PM
Newbie Coder
Join Date: Jan 2010
Posts: 27
Thanks: 5
Thanked 0 Times in 0 Posts
thanks Jcbones
i'm trying to do this 3 thing
1. 2 days ago instead of 2 Days, 1 Hours, 59 Minutes ago
2. 1 month ago if exceed 30/31 days
3. 1 year ago if exceed 1 year
any help ?
Last edited by sarahmx; 03-08-10 at 11:40 PM .
03-09-10, 01:37 AM
Newbie Coder
Join Date: Jan 2010
Posts: 27
Thanks: 5
Thanked 0 Times in 0 Posts
ok i found this...i want to do some like this..using the jcbones functions
PHP Code:
function _ago ( $tm , $rcs = 0 ) { $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 == 1 )&&( $v >= 1 )&&(( $cur_tm - $_tm ) > 0 )) $x .= time_ago ( $_tm ); return $x ; }
second','minute','hour','day','week','month','year ','decade'
Last edited by sarahmx; 03-09-10 at 01:42 AM .
03-09-10, 07:59 PM
Aspiring Coder
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
The Following User Says Thank You to Jcbones For This Useful Post:
03-09-10, 08:29 PM
Newbie Coder
Join Date: Jan 2010
Posts: 27
Thanks: 5
Thanked 0 Times in 0 Posts
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off