Welcome Guest, Not a member yet? Register   Sign In
Nice Dates
#1

[eluser]reaktivo[/eluser]
Does anybody know of a helper for printing text dates as is:

Moments ago...
One year ago...
Yesterday


etc. ?

Thanks!
#2

[eluser]Derek Allard[/eluser]
I sure do Wink
#3

[eluser]Colin Williams[/eluser]
Ssgt Wales has a good version of it too: http://ellislab.com/forums/viewthread/84271/

His does 'Just now', 'xx hours ago', 'xx days ago', or 'xx minutes ago' but only in quarter-hour segments.
#4

[eluser]phpwebdev[/eluser]
[quote author="reaktivo" date="1219801085"]Does anybody know of a helper for printing text dates as is:

Moments ago...
One year ago...
Yesterday


etc. ?

Thanks![/quote]

Check this function
Code:
timespan()
and if needed - modify it
Regards
#5

[eluser]thurting[/eluser]
Some native PHP like the following also works"

date(string $format, strtotime('-1 day'))
#6

[eluser]reaktivo[/eluser]
Thanks for all the replies, I ended up using Michael Wales version, I just updated to display weeks and months, and in Spanish, here's the function for anybody who could need it:

Code:
<?
//Original version by Michael Wales
//Updated to support weeks and months by Marcel Miranda <[email protected]>
function days_ago($seconds = 1, $capitalize = FALSE) {
    $word = $capitalize ? "Hace" : "hace";
    if (!is_numeric($seconds)) {
        $seconds = strtotime($seconds);
    }
    $seconds = now() - $seconds;

    if ($seconds < 0) {
        return "$word unos momentos";
    }

    $days = floor($seconds / 86400);
    if ($days > 0) {
        if($days > 7) {
            if($days < 10) {
                return "$word una semana";
            }elseif($days < 30) {
                $weeks = round($days / 7);
                return "$word " . $weeks . " semanas";
            }else{
                if($days < 40) {
                    return "$word un mes";
                }else{
                    $months = round($days/30);
                    return "$word " . $months . " meses";
                }
            }
        }else{
            return "$word " . $days . " días";
        }

    }

    $hours = floor($seconds / 3600);
    if ($hours > 0) {
        if ($hours == 1) {
            return "$word una hora";
        }
        return "$word " . $hours . " horas";
    }

    $minutes = floor($seconds / 60);
    if ($minutes > 52) {
        return "$word una hora";
    } elseif ($minutes > 38) {
        return "$word 45 minutos";
    } elseif ($minutes > 24) {
        return "$word 30 minutos";
    } elseif ($minutes > 10) {
        return "$word 15 minutos";
    } else {
        return "$word unos momentos";
    }
}

?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB