Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 3 of 3 FirstFirst 123
Results 21 to 30 of 30
  1. #21
    Join Date
    Jul 2005
    Location
    Leeds
    Posts
    947
    Tokens
    0
    Habbo
    Flumples

    Default

    I'm confused... That's exactly how I've got it coded on my page.

    E.g.

    PHP Code:
    <html>
    <head>
    </head>
    <body>
    <?php 


    function plural($num) {
        if (
    $num != 1)
            return 
    "s";
    }
     
    function 
    getRelativeTime($date) {
        
    $diff time() - $date;
        if (
    $diff<60)
            return 
    $diff " second" plural($diff) . " ago";
        
    $diff round($diff/60);
        if (
    $diff<60)
            return 
    $diff " minute" plural($diff) . " ago";
        
    $diff round($diff/60);
        if (
    $diff<24)
            return 
    $diff " hour" plural($diff) . " ago";
        
    $diff round($diff/24);
        if (
    $diff<7)
            return 
    $diff " day" plural($diff) . " ago";
        
    $diff round($diff/7);
        if (
    $diff<4)
            return 
    $diff " week" plural($diff) . " ago";
        return 
    "on " date("F j, Y"strtotime($date));
    }

    // Unix timestamp for today at 17:21:19, replace this with a timestamp for whenever you want
    $stampystamp 1295803279;

    // Display the number of seconds/minutes/hours/days/weeks since the timestamp
    echo getRelativeTime($stampystamp);

     
    ?>
    </body>
    </html>
    I take it I'm doing something wrong..? Sorry like I said earlier my php knowledge is very limited!

  2. #22
    Join Date
    Jun 2008
    Location
    United Kingdom
    Posts
    2,015
    Tokens
    568

    Latest Awards:

    Default

    Quote Originally Posted by Flumples View Post
    I'm confused... That's exactly how I've got it coded on my page.

    E.g.

    PHP Code:
    <html>
    <head>
    </head>
    <body>
    <?php 


    function plural($num) {
        if (
    $num != 1)
            return 
    "s";
    }
     
    function 
    getRelativeTime($date) {
        
    $diff time() - $date;
        if (
    $diff<60)
            return 
    $diff " second" plural($diff) . " ago";
        
    $diff round($diff/60);
        if (
    $diff<60)
            return 
    $diff " minute" plural($diff) . " ago";
        
    $diff round($diff/60);
        if (
    $diff<24)
            return 
    $diff " hour" plural($diff) . " ago";
        
    $diff round($diff/24);
        if (
    $diff<7)
            return 
    $diff " day" plural($diff) . " ago";
        
    $diff round($diff/7);
        if (
    $diff<4)
            return 
    $diff " week" plural($diff) . " ago";
        return 
    "on " date("F j, Y"strtotime($date));
    }

    // Unix timestamp for today at 17:21:19, replace this with a timestamp for whenever you want
    $stampystamp 1295803279;

    // Display the number of seconds/minutes/hours/days/weeks since the timestamp
    echo getRelativeTime($stampystamp);

     
    ?>
    </body>
    </html>
    I take it I'm doing something wrong..? Sorry like I said earlier my php knowledge is very limited!
    Hmm I'm stumped then. I tested the code when I first posted it, it worked fine, but I just copied and pasted the exact same code and it's displaying the epoch thing. I wrongly assumed you were just making a stupid mistake at first, but I'm having the same problem.

    Anyone else fancy jumping in on this?

  3. #23
    Join Date
    Feb 2008
    Location
    London, UK
    Posts
    15,747
    Tokens
    25,786
    Habbo
    Mr-Trainor

    Latest Awards:

    Default

    I tried it yesterday as well and had the same problem. My PHP knowledge isn't much though . When I changed the timestamp (I change it too 2/3 days ago) it worked fine.

  4. #24
    Join Date
    Feb 2006
    Location
    Scotland
    Posts
    2,087
    Tokens
    138

    Latest Awards:

    Default

    PHP Code:
    <?php 

    date_default_timezone_set
    ('Europe/London');

    function 
    plural($num) {
        if (
    $num != 1)
            return 
    "s";
    }
     
    function 
    getRelativeTime($date) {
        
    $diff time() - $date;
        if (
    $diff<60)
            return 
    $diff " second" plural($diff) . " ago";
        
    $diff round($diff/60);
        if (
    $diff<60)
            return 
    $diff " minute" plural($diff) . " ago";
        
    $diff round($diff/60);
        if (
    $diff<24)
            return 
    $diff " hour" plural($diff) . " ago";
        
    $diff round($diff/24);
        if (
    $diff<7)
            return 
    $diff " day" plural($diff) . " ago";
        
    $diff round($diff/7);
        if (
    $diff<4)
            return 
    $diff " week" plural($diff) . " ago";
            
        return 
    "on " date("F j, Y"$date);
    }

    // Unix timestamp for today at 17:21:19, replace this with a timestamp for whenever you want
    $stampystamp 1295803279;

    // Display the number of seconds/minutes/hours/days/weeks since the timestamp
    echo getRelativeTime($stampystamp);

     
    ?>
    strtotime is used to "Parse about any English textual datetime description into a Unix timestamp" - The value that was being passed in was the timestamp

  5. #25
    Join Date
    Jul 2005
    Location
    Leeds
    Posts
    947
    Tokens
    0
    Habbo
    Flumples

    Default

    Quote Originally Posted by Johno View Post
    PHP Code:
    <?php 

    date_default_timezone_set
    ('Europe/London');

    function 
    plural($num) {
        if (
    $num != 1)
            return 
    "s";
    }
     
    function 
    getRelativeTime($date) {
        
    $diff time() - $date;
        if (
    $diff<60)
            return 
    $diff " second" plural($diff) . " ago";
        
    $diff round($diff/60);
        if (
    $diff<60)
            return 
    $diff " minute" plural($diff) . " ago";
        
    $diff round($diff/60);
        if (
    $diff<24)
            return 
    $diff " hour" plural($diff) . " ago";
        
    $diff round($diff/24);
        if (
    $diff<7)
            return 
    $diff " day" plural($diff) . " ago";
        
    $diff round($diff/7);
        if (
    $diff<4)
            return 
    $diff " week" plural($diff) . " ago";
            
        return 
    "on " date("F j, Y"$date);
    }

    // Unix timestamp for today at 17:21:19, replace this with a timestamp for whenever you want
    $stampystamp 1295803279;

    // Display the number of seconds/minutes/hours/days/weeks since the timestamp
    echo getRelativeTime($stampystamp);

     
    ?>
    strtotime is used to "Parse about any English textual datetime description into a Unix timestamp" - The value that was being passed in was the timestamp
    Ooo thats sorted it, thanks! It's still not what I was after though.

    I needed a counter that displayed the number of days since a certain date, not weeks or anything like that, just days. So a counter that increases by 1 each day. Basically it's to go on a news articles page thats styled to look like a newspaper and has 'Issue #6' or whatever in the top corner and I needed that issue number to go up by 1 each day just to make it look a bit more realistic.

    I managed to sort it though, no idea how and this is probably really messy coding, but it seems to work

    PHP Code:
    <?php 
    function plural($num) {
        if (
    $num != 1)
            return 
    "s";
    }
    function 
    getRelativeTime($date) {
        
    $diff time() - $date;
        if (
    $diff<60)
            return 
    $diff " second" plural($diff) . " ago";
        
    $diff round($diff/60);    
        if (
    $diff<60)
            return 
    $diff " minute" plural($diff) . " ago";
        
    $diff round($diff/60);
        if (
    $diff<24)
            return 
    $diff " hour" plural($diff) . " ago";
        
    $diff round($diff/24);
        if (
    $diff/7)
            return 
    $diff "" "";
        return 
    "on " date("F j, Y"strtotime($date));
    }
    // Unix timestamp
    $stampystamp 1295803279;
    // Display the number of seconds/minutes/hours/days/weeks since the timestamp
    echo
    ?>

  6. #26
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    Just days you sayyy?

    PHP Code:
    <?php

    /**
     * Function that you can c/p
     **/

    function daysSince$date )
    {
        
    $from strtotime$date );
        
    $to time();
        
    $time $to $from;
        
        return 
    round( ( ( ( $time 60 ) / 60 ) / 24 ), 0);
    }

    /**
     * Usage - should output 8 from 21st :)
     **/
     
    echo daysSince'8 February 2011' );

    ?>
    Hope that helps.

    P.S You can tell when I'm stressed and up late when I post on HxF ^_^ and HAIII TRINITY
    Last edited by Source; 21-02-2011 at 03:14 AM.

  7. #27
    Join Date
    Jun 2008
    Location
    United Kingdom
    Posts
    2,015
    Tokens
    568

    Latest Awards:

    Default

    Quote Originally Posted by Source View Post
    Just days you sayyy?

    PHP Code:
    <?php

    /**
     * Function that you can c/p
     **/

    function daysSince$date )
    {
        
    $from strtotime$date );
        
    $to time();
        
    $time $to $from;
        
        return 
    round( ( ( ( $time 60 ) / 60 ) / 24 ), 0);
    }

    /**
     * Usage - should output 8 from 21st :)
     **/
     
    echo daysSince'8 February 2011' );

    ?>
    Hope that helps.

    P.S You can tell when I'm stressed and up late when I post on HxF ^_^ and HAIII TRINITY
    HAIII MATT

    I don't want to get shouted at for making a 'pointless' post, so erm... that's some good code that. Flumples, you should totally use it.

  8. #28
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    We must catchup soon my dear.

    If anyone is interested how the days are worked out, then yeah. A timestamp is the seconds that have passed since said 1970 date. Take the timestamp of today, minus the timestamp of the date you want to work out how many days have passed will leave you with how many seconds have passed from input date, to this second. From there it's as simple as dividing by 60 for minutes, dividing by 60 again for hours and lastly dividing by 24 to leave us with days.

    Fun.


    www.fragme.co = a project.

  9. #29
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Mattt! I love you, k thx.

    Anyways I don't care about a pointless post, so this is pointless.

  10. #30
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    Mattt! I love you, k thx.
    Always knew it ^_^ hahaha, how are you Mr Mingle? Mingle Graphics going well?

    Also for the sake of using less code, you could use something like:

    PHP Code:
    <?php 

    /** 
     * Function that you can c/p 
     **/ 

    function daysSince$date 
    {
        return 
    round( ( ( ( time() - strtotime$date ) / 60 ) / 60 ) / 24 ), ); 


    /** 
     * Usage - should output 8 from 21st :) 
     **/ 
      
    echo daysSince'8 February 2011' ); 

    ?>


    www.fragme.co = a project.

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •