1

Topic: How to change date display from 01.11.2007 to "2 weeks ago"?

How to change date display from 01.11.2007 to "2 weeks ago"?

No a have this:
2007-10-31 23:47:50

But I would like "Two weeks ago".


A would like:

Today (is)
Yesterday (is)
Now there is turning to "2007-11-08", but I would like "2 days ago"
"3 days ago"
4
5
6
"Week ago"
"2 weeks ago"
"3 weeks ago"
"4 weeks ago"
and only the:
2007-10-08

???

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

Open include/functions.php

find:

function format_time($timestamp, $date_only = false)
{
    global $pun_config, $lang_common, $pun_user;

    if ($timestamp == '')
        return $lang_common['Never'];

    $diff = ($pun_user['timezone'] - $pun_config['o_server_timezone']) * 3600;
    $timestamp += $diff;
    $now = time();

    $date = date("d-m-y", $timestamp);
    $today = date($pun_config['o_date_format'], $now+$diff);
    $yesterday = date($pun_config['o_date_format'], $now+$diff-86400);

    if ($date == $today)
        $date = $lang_common['Today'];
    else if ($date == $yesterday)
        $date = $lang_common['Yesterday'];

    if (!$date_only)
        return $date.' '.date($pun_config['o_time_format'], $timestamp);
    else
        return $date;
}

REPLACE WITH:

function format_time($timestamp, $date_only = false)
{
    global $pun_config, $lang_common, $pun_user;

    if (!$date_only)
        {
            $diff = time() - $timestamp;
            $rest = ($diff % 3600);
            $restdays = ($diff % 86400);
            $restweeks = ($diff % 604800);
            $weeks = ($diff - $restweeks) / 604800;
            $days = ($diff - $restdays) / 86400;
            $hours = ($diff - $rest) / 3600;
            $seconds = ($rest % 60);
            $minutes = ($rest - $seconds) / 60;
            if ($timestamp == '')
                return $lang_common['Never'];
            if($weeks > 1)
                return $date."$weeks weeks ago";
            elseif($days > 1)
                return $date."$days days ago";
            elseif($hours > 1)
                return $date."$hours hours ago";
            elseif ($hours == 1)
                return $date."1 hour, $minutes mins ago";
            elseif ($minutes == 0)
                return $date."$seconds seconds ago";
            elseif ($minutes == 1)
                return $date."1 minute ago";
            elseif ($seconds < 60)
                return $date."$minutes mins ago";
        }
        else{
            $diff = ($pun_user['timezone'] - $pun_config['o_server_timezone']) * 3600;
            $timestamp += $diff;
            $now = time();

            $date = date($pun_config['o_date_format'], $timestamp);
            $today = date($pun_config['o_date_format'], $now+$diff);
            $yesterday = date($pun_config['o_date_format'], $now+$diff-86400);

            return $date;
           }
}

Can't find the original post... sorry.

Post hoc ergo propter hoc

3 (edited by Ahmed 2007-11-10 17:26)

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

Thanks, it is working, but litlebit too extreme.

I have posts like "29 weeks ago". It would be enough if after one or two months there would be date (2007-06-19).

Reason why I wanted this was to make more easy to understand when post has been written, - without some calculations. Also if there is only "today" and "yesterday" then post which is done 3 days ago looks the same old as one which is 3 month ago.

Now is again may be too many numbers. Now 3 minutes or 3 houers ago has again nummber as 3 weeks (and later possibly 3 month, 3 years) ago.

So another thing which would be better - that when is written today or yesterday, then would be written "Today, 3 hours ago" and not just "3 hours ago".
But after "yesterday" could be this system which changes to 2007-09-25 after month...

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

This should show:
Today, 23 seconds ago by x
Today, 2 mins ago by x
Today, 4 hours ago by x
Yesterday, 35 hours ago by x
3 days ago by x
11-10-07 by x

Haven't tested it fully yikes

function format_time($timestamp, $date_only = false)
{
    global $pun_config, $lang_common, $pun_user;

    if (!$date_only)
        {
            $over_a_week = date("d-m-y", $timestamp);
            $diff = time() - $timestamp;
            $rest = ($diff % 3600);
            $restdays = ($diff % 86400);
            $restweeks = ($diff % 604800);
            $weeks = ($diff - $restweeks) / 604800;
            $days = ($diff - $restdays) / 86400;
            $hours = ($diff - $rest) / 3600;
            $seconds = ($rest % 60);
            $minutes = ($rest - $seconds) / 60;
            if ($timestamp == '')
                return $lang_common['Never'];
            if($weeks > 1)
                return $over_a_week;
            elseif($days > 1)
                return $date."$days days ago";
            elseif($hours > 23)
                return "Yesterday, $hours hours ago";
            elseif($hours > 1)
                return "Today, $date $hours hours ago";
            elseif ($hours == 1)
                return "Today, $date 1 hour, $minutes mins ago";
            elseif ($minutes == 0)
                return "Today, $date  $seconds seconds ago";
            elseif ($minutes == 1)
                return "Today, $date  1 minute ago";
            elseif ($seconds < 60)
                return "Today, $date  $minutes mins ago";
        }
        else{
            $diff = ($pun_user['timezone'] - $pun_config['o_server_timezone']) * 3600;
            $timestamp += $diff;
            $now = time();

            $date = date($pun_config['o_date_format'], $timestamp);
            $today = date($pun_config['o_date_format'], $now+$diff);
            $yesterday = date($pun_config['o_date_format'], $now+$diff-86400);

            return $date;
           }
}
Post hoc ergo propter hoc

5

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

It works. Only I guess there is no more "weeks" just "days". Turning to date after some 14 days or so...

For me last modification is good. Hope other forum users would accept.

Thanks.

Have a look:

http://www.forum.islammuslim.lv/index.php

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

actually that is kewl. im going to apply this to punlancer.com... so i can see sorta when the last post was made..



thanks......

Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

7

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

But there is problem. Now I have posts "Today, 20 hours ago by ahmeds" but they surely was made 20 hours ago, but that was YESTERDAY...


http://www.forum.islammuslim.lv/

May be I just should replace new "functions.php" with old one, and at midnight 00:00 change to new one???

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

Can you change too this one fast, and see if it's wrong or not...

function format_time($timestamp, $date_only = false)
{
    global $pun_config, $lang_common, $pun_user;

    if ($timestamp == '')
        return $lang_common['Never'];

    $diff = ($pun_user['timezone'] - $pun_config['o_server_timezone']) * 3600;
    $timestamp += $diff;
    $now = time();

    $date = date("d-m-y", $timestamp);
    $today = date($pun_config['o_date_format'], $now+$diff);
    $yesterday = date($pun_config['o_date_format'], $now+$diff-86400);

    if ($date == $today)
        $date = $lang_common['Today'];
    else if ($date == $yesterday)
        $date = $lang_common['Yesterday'];

    if (!$date_only)
        return $date.' '.date($pun_config['o_time_format'], $timestamp);
    else
        return $date;
}
Post hoc ergo propter hoc

9 (edited by Ahmed 2007-11-11 19:26)

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

????

????

????

This looked like original and is (with minor differences (d-m-y))... And there is no "today" and "yesterday" at all...

10

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

The problem is that now mod counts last 24 hours as "today", but "24-48 hours ago" as yesterday. But this is not correct. Becouse if I post at 4.am, then 9 hours ago is not "today", but yesterday. (Yesterday at 7.pm...)

Any solutions?

11

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

Can't find any thing but try this...

function format_time($timestamp, $date_only = false)
{
    global $pun_config, $lang_common, $pun_user;

    if (!$date_only)
        {
            $over_a_week = date("d-m-y", $timestamp);
            $diff = time() - $timestamp;
            $rest = ($diff % 3600);
            $restdays = ($diff % 86400);
            $restweeks = ($diff % 604800);
            $weeks = ($diff - $restweeks) / 604800;
            $days = ($diff - $restdays) / 86400;
            $hours = ($diff - $rest) / 3600;
            $seconds = ($rest % 60);
            $minutes = ($rest - $seconds) / 60;
            if ($timestamp == '')
                return $lang_common['Never'];
            if($weeks > 1)
                return $over_a_week;
            elseif($days > 1)
                return $date."$days days ago";
            elseif($days == 1)
                return "Yesterday, $hours hours ago";
            elseif($hours > 1)
                return "Today, $date $hours hours ago";
            elseif ($hours == 1)
                return "Today, $date 1 hour, $minutes mins ago";
            elseif ($minutes == 0)
                return "Today, $date  $seconds seconds ago";
            elseif ($minutes == 1)
                return "Today, $date  1 minute ago";
            elseif ($seconds < 60)
                return "Today, $date  $minutes mins ago";
        }
        else{
            $diff = ($pun_user['timezone'] - $pun_config['o_server_timezone']) * 3600;
            $timestamp += $diff;
            $now = time();

            $date = date($pun_config['o_date_format'], $timestamp);
            $today = date($pun_config['o_date_format'], $now+$diff);
            $yesterday = date($pun_config['o_date_format'], $now+$diff-86400);

            return $date;
           }
}
Post hoc ergo propter hoc

12

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

I do not understood, - what is changes? I see nothing changed... The same problem that any last 24 hours is today...

13

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

elseif($hours > 23)
to
elseif($days == 1)

Post hoc ergo propter hoc

14

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

Tjalve wrote:

elseif($hours > 23)
to
elseif($days == 1)

Why did noone worked?

15

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

Don't know... works fine here. Haven't seen any thing wrong with today/yesterday.

I can't figure it out.

Post hoc ergo propter hoc

16

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

So...

Have anybody idea how to make that date display wiould work in 3 ways:
1) counting real time ar watching is it realy today or yesterday
2) after that hours, days
3) and after some 14 days switching to ddmmyy.

Now problem is that, that every last 24 hours is counted as today, even if post was posted yesterday 5 hours ago.
The same problem with yesterday, which is every 24-48 hours ago.

17

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

Anybody?
It shouldnt be difficult...

Original is:
Today 01:05:06 by Smartys
Yesterday 23:35:54 by AdsBB
2008-01-06 21:20:02 by sypie


My incomplete modification have:
Today, 22 mins ago - by ahmeds
Yesterday, 47 hours ago - by ahmeds
3 days ago - by Maimuna
12-11-07 - by ahmeds

So almost everything is correct except trigers for "today" and "yesterday" ir my forum modification. It is counting any 24 and 48 hours, but should be on the same trigers as on original (counting depends on 00:01 am).

18 (edited by FSX 2008-01-15 12:17)

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

I made this for my system:

function formattime($timestamp){
    
    // Set some vars
    $gmtunix    = $timestamp - date('Z', $timestamp); // This returns an GMT unix timestamp
    $diff        = time() - $gmtunix;
    $hour        = 3600;
    $day        = (24 * $hour);
    $week        = (7 * $day);
    
    $days    = floor($diff / $day);
    $weeks    = floor($diff / $week);
    $daysweeks = $days - ($weeks * 7);
    
    // $time = date("d/m/Y H:i", $timestamp - date('Z', $time));
    $date = date('d - m - Y', $timestamp - date('Z', $timestamp));
    $time = date('H:i', $timestamp - date('Z', $timestamp));
    
    if ($days == 0)
        return 'Today at '.$time;
    elseif ($days == 1)
        return 'Yesterday at '.$time;
    elseif ($days > 1 && $days < 7)
        return $days.' days ago at '.$time;
    elseif ($weeks == 1 && $daysweeks < 7) 
        return $weeks.' weeks and '.$daysweeks.' days ago at '.$time;
    elseif ($weeks == 2 && $daysweeks < 7) 
        return $weeks.' weeks and '.$daysweeks.' days ago at '.$time;
    elseif ($weeks >= 1 && $daysweeks <= 2)
        return $weeks.' weeks ago at '.$time;
    else
        return $date;
}

It converts the inputted timestamp to GMT time.
And it displays something like this:
- Today at 10:16
- Yesterday at 9:06
- 4 Days ago at 10:16
- 1 week and 2 days ago at 10:16

Maybe you can use it. I haven't tested it good, just made it today.

19

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

- Today at 10:16
- Yesterday at 9:06
- 4 Days ago at 10:16
- 1 week and 2 days ago at 10:16
===========
It works. Only when now I see it, I guess it would be littlebit better if it would be more "simplified" appereance:

- Today at 10:16
- Yesterday at 9:06
- 4 Days ago
- 9 Days ago
- 26 - 12 - 2007

This simplisness would help more easy to catch post dates.

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

why would it not show AM or PM as well?

21 (edited by Ahmed 2008-01-15 21:32)

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

bingiman wrote:

why would it not show AM or PM as well?

Well, I beter like 21:51 than 10:51PM.

But there is some problem. Clock ir 2 hours less. Clock is London, but forum is in Latvia, +2h.
So just posted - 21:20, but should be 23:20. Is it some code problem, or my hostingserver changed something?



Huge thanks, btw. This problem was in my forum for several months.

22

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

The function I posted was for the cms I'm building. I haven't have settings for the time so the function outputs GMT time.

You should not replace the orginal time function of punbb with my function, it isn't made for punbb. I just tought you could use the code ^^.

23 (edited by Ahmed 2008-01-15 22:26)

Re: How to change date display from 01.11.2007 to "2 weeks ago"?

FSX wrote:

The function I posted was for the cms I'm building. I haven't have settings for the time so the function outputs GMT time.

You should not replace the orginal time function of punbb with my function, it isn't made for punbb. I just tought you could use the code ^^.

I replaced. Can You show me what I was need to be left?

:-))