SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: web 2.0 dates

  1. #1
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    web 2.0 dates

    Hey fellow programmers,

    just wondering if anyone has a code snippet or has found a tutorial on how to build web 2.0 style dates ~ i.e. "last seen online 2 hours ago", "last seen online yesterday", "last seen online 2 months ago" etc

    Cheers
    _________________________/Az.________________

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    Most likely just date manipulation based on the users last logged in time, here is a little script I wrote that gives you the difference in days. To use hours have a look at the date functions in the php manual......

    PHP Code:
    function getdays($day1,$day2)
    {
        
    $diff =  round((strtotime($day2)-strtotime($day1))/(24*60*60),0);
            if(
    eregi('-'$diff)) {
                
    $dr str_replace("-"""$diff);
                    
    $suffix = ($dr 1) ? ' days ' ' day ';
                  
    $out 'last seen '$dr $suffix .' ago';
            } 
        return 
    $out;
    }

    $begin date("Y-m-d"); // we set today as an example
    $end "2006-09-19";

    echo 
    getdays($begin,$end); 
    Cheers

    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,561
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just wondering if anyone has a code snippet or has found a tutorial on how to build web 2.0 style dates ~ i.e. "last seen online 2 hours ago"
    I am amazed you called it Web 2.0 style date?

  4. #4
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cheers spikeZ, i'll work of your code on that one.

    lol - why are you suprised? its so web 2.0 it hurts !
    _________________________/Az.________________

  5. #5
    is_empty(2); foofoonet's Avatar
    Join Date
    Mar 2006
    Posts
    1,000
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    He only said that because he has a Web 1.0 hairdo.
    Upgrading to Mysql 5? Auto-increment fields now strict
    use NULL
    Or zero or leave the field name out completely.

  6. #6
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ha ha ha - web 2.0 is such a dirty word, but when a client specifically asks for a web 2.0 style site, what can you do but deliver?

    But i feel dirty, real dirty.
    _________________________/Az.________________

  7. #7
    is_empty(2); foofoonet's Avatar
    Join Date
    Mar 2006
    Posts
    1,000
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you do accept Money 2.0 dont you?

    You can't have your Cake 2.0 and it Eat It 1.0.

    tehee... Still I cant help it, I have to ask you, how will your client know the difference between web 1.0 and web 2.0 dates?

    I mean, do they auto-refresh with Ajax or what? Are the dates clickable - and form part of a tag-cloud?

    I am really curious, and, well, I might be envious....
    Upgrading to Mysql 5? Auto-increment fields now strict
    use NULL
    Or zero or leave the field name out completely.

  8. #8
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol - well the whole date thing started when I did the design, I put down things like "this comment was posted 3 days ago" and the client was like "oooh, I like how there aren't stupid dates there, but instead some friendly text, how web 2.0" etc

    his one of those clients that know enough to hinder you, but not enough to realise how much work is involved :P
    _________________________/Az.________________

  9. #9
    is_empty(2); foofoonet's Avatar
    Join Date
    Mar 2006
    Posts
    1,000
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL (yeah, really I did....)

    I'm off now, but that made me larf. So like, the mysql date_format() function is web 2.0 ready...

    keep well.
    Upgrading to Mysql 5? Auto-increment fields now strict
    use NULL
    Or zero or leave the field name out completely.

  10. #10
    SitePoint Addict bkennedy's Avatar
    Join Date
    Aug 2004
    Location
    michigan
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's what I use:

    PHP Code:
    //$time is a unix timestamp

    function relative_date($time) {
        
    $today strtotime(date('M j, Y'));
        
    $reldays = ($time $today)/86400;
        if (
    $reldays >= && $reldays 1) {
            return 
    'Today';
        } else if (
    $reldays >= && $reldays 2) {
            return 
    'Tomorrow';
        } else if (
    $reldays >= -&& $reldays 0) {
            return 
    'Yesterday';
        }
        if (
    abs($reldays) < 7) {
            if (
    $reldays 0) {
            
    $reldays floor($reldays);

                return 
    'In ' $reldays ' day' . ($reldays != 's' '');
            } else {
                
    $reldays abs(floor($reldays));
                return 
    $reldays ' day'  . ($reldays != 's' '') . ' ago';
            }
        }
        if (
    abs($reldays) < 21) {
            return 
    date('l, F j',$time $time time());
        } else {
            return 
    date('l, F j, Y',$time $time time());
        }

    modify to your heart's content
    ----------------
    bob.kennedy
    ----------------

  11. #11
    Non-Member
    Join Date
    Jul 2005
    Posts
    606
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    gawd you people are so last year

    web 3.0 is the future


Bookmarks

Posting Permissions

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