TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-27-2009, 07:59 PM   #1 (permalink)
The Contributor
 
Sirupsen's Avatar
 
Join Date: May 2009
Posts: 53
Thanks: 2
Sirupsen is on a distinguished road
Default TimeElapsed

Hello! I'm trying to make a scrupt which calculates estimated time since post, like on twitter. I kinda just want it to show minutes, untill its hours, show hours untill its days ago - and when it's at days, show the full date. But would I do this?

But yeah, I'm really really unsure how to do this? Anyone can help me a bit? Here's the code I have so far, if someone know a site or script for this I'd love a look on it..:

PHP Code:
    function calcElapsedTime($time){

        
$diff time()-$time;
        
$yearsDiff floor($diff/60/60/24/365);
        
$diff -= $yearsDiff*60*60*24*365;
        
$monthsDiff floor($diff/60/60/24/30);
        
$diff -= $monthsDiff*60*60*24*30;
        
$weeksDiff floor($diff/60/60/24/7);
        
$diff -= $weeksDiff*60*60*24*7;
        
$daysDiff floor($diff/60/60/24);
        
$diff -= $daysDiff*60*60*24;
        
$hrsDiff floor($diff/60/60);
        
$diff -= $hrsDiff*60*60;
        
$minsDiff floor($diff/60);
        
$diff -= $minsDiff*60;
        
$secsDiff $diff;
        
        
$ago 'ago';
        
$years $yearsDiff.' year'.(($yearsDiff <> 1) ? "s" "");
        
$months $monthsDiff.' month'.(($monthsDiff <> 1) ? "s" "");
        
$weeks $weeksDiff.' week'.(($weeksDiff <> 1) ? "s" "");
        
$days $daysDiff.' day'.(($daysDiff <> 1) ? "s" "");
        
$hours $hrsDiff.' hour'.(($hrsDiff <> 1) ? "s" "");
        
$mins $minsDiff.' minute'.(($minsDiff <> 1) ? "s" "");
        
$secs $secsDiff.' second'.(($secsDiff <> 1) ? "s" "");
        
        if(
$years 1) {
            
$years "";
        }    
        
        if(
$months 1) {
            
$months "";
        }        
        
        if(
$weeks 1) {
            
$weeks "";
        }        

        if(
$days 1) {
            
$days "";
        }        
        
        if(
$hours 1) {
            
$hours "";
        }
        
        if(
$mins 1) {
            
$mins "";
        }
        
        if(
$secs 1) {
            
$secs "";
        }
        
        return (
'
        
            '
.$years.
            '
.$months.'
            '
.$weeks.'
            '
.$days.
            '
.$hours.
            '
.$mins.
            '
.$secs.'
            '
.$ago.'
        
        '
);


Last edited by Sirupsen : 05-27-2009 at 08:37 PM.
Send a message via AIM to Sirupsen Send a message via MSN to Sirupsen Send a message via Yahoo to Sirupsen Send a message via Skype™ to Sirupsen
Sirupsen is offline  
Reply With Quote
Old 05-28-2009, 01:27 AM   #2 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

PHP/TIME

I think this should help.



-Cf
codefreek is offline  
Reply With Quote
Old 05-28-2009, 05:52 AM   #3 (permalink)
The Contributor
 
Sirupsen's Avatar
 
Join Date: May 2009
Posts: 53
Thanks: 2
Sirupsen is on a distinguished road
Default

Thanks a lot! I found what I needed, I had only been looking at Date function on php net. :)
Send a message via AIM to Sirupsen Send a message via MSN to Sirupsen Send a message via Yahoo to Sirupsen Send a message via Skype™ to Sirupsen
Sirupsen is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:30 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design