| can anyone tell me why my script is not returning anything??? plz?? <?php function distanceOfTimeInWords($fromTime, $toTime = 0, $showLessThanAMinute = false) { $distanceInSeconds = round(abs($toTime - $fromTime)); $distanceInMinutes = round($distanceInSeconds / 60); if ( $distanceInMinutes <= 1 ) { if ( !$showLessThanAMinute ) { return ($distanceInMinutes == 0) ? 'less than a minute' : '1 minute'; } else { if ( $distanceInSeconds < 5 ) { return 'less than 5 seconds'; } if ( $distanceInSeconds < 10 ) { return 'less than 10 seconds'; } if ( $distanceInSeconds < 20 ) { return 'less than 20 seconds'; } if ( $distanceInSeconds < 40 ) { return 'about half a minute'; } if ( $distanceInSeconds < 60 ) { return 'less than a minute'; } return '1 minute'; } } if ( $distanceInMinutes < 45 ) { return $distanceInMinutes . ' minutes'; } if ( $distanceInMinutes < 90 ) { return 'about 1 hour'; } if ( $distanceInMinutes < 1440 ) { return 'about ' . round(floatval($distanceInMinutes) / 60.0) . ' hours'; } if ( $distanceInMinutes < 2880 ) { return '1 day'; } if ( $distanceInMinutes < 43200 ) { return 'about ' . round(floatval($distanceInMinutes) / 1440) . ' days'; } if ( $distanceInMinutes < 86400 ) { return 'about 1 month'; } if ( $distanceInMinutes < 525600 ) { return round(floatval($distanceInMinutes) / 43200) . ' months'; } if ( $distanceInMinutes < 1051199 ) { return 'about 1 year'; } return 'over ' . round(floatval($distanceInMinutes) / 525600) . ' years'; echo $distanceInSeconds; distanceofTimeInWords(2003,2005); }
?> |
|
| hello Arup Debnath, may i know how to use this function? what value $fromTime should be? sorry.. hehe.. i'm so lazy to read u'r function. |
|
| remove these lines echo $distanceInSeconds; distanceofTimeInWords(2003,2005); then type (outside the function) echo distanceofTimeInWords(2003,2005);
may be that's what you want.. |
|
| ok. also try to read this: http://www.mdj.us/web-development/php-programming/another-variation-on-the-time-ago-php-function-use-mysqls-datetime-field-type/ |
|
| dude it worked!! thanks... Slamet Aprilianto |
|
| youre welcome.. |
|
| but there is a problem,, it echoed out "less than a minute".. ??? |
|
| thanks Pororo |
|
| because that is what ur code said, $distanceInSeconds = round(abs(2005 - 2003)) = 2 $distanceInMinutes = round(abs(2/60)) = round(0.03) = 0 |
|
| oh i missed that... k thanks... |
Tidak ada komentar:
Posting Komentar