Time Difference Documentation

This plugin requires PHP version > 5.3.0 and will display an error otherwise.

Wrap your conditionals in {exp:cc_time_difference} tags.

Contents

Parameters

The tag has the following parameters:

time_1=""

The first time to calculate difference with. (Required.)

time_2=""

The second time to calculate difference with. (Required.)

inclusive="yes"

Whether to include the total number of units, or only the remainder.

The order the times are passed does not matter, the absolute difference will be calculated.

Variables

CC Time Difference creates the following variables to use:

{years}

The total number of years between the two dates.

{months}

The total number of months between the two dates.

{days}

The total number of days between the two dates.

{weeks}

The total number of weeks between the two dates.

{hours}

The total number of hours between the two dates.

{minutes}

The total number of minutes between the two dates.

{seconds}

The total number of seconds between the two dates.

Conditional Variables

CC Time Difference creates the following conditional parameters to use:

{compare}

Compares the two times and returns a negative integer if time_1 is earlier, a positive integer if time_2 is earlier or 0 if they are equal.

Example

{exp:channel:entries channel="compare_time"}
    {exp:cc_time_difference time_1="{entry_date}" time_2="{current_time}"}
        {if compare < 0}
            {if days == 1}
                Posted 1 day ago.
            {if:elseif weeks < 1}
                Posted {days} days ago.
            {if:elseif weeks == 1}
                Posted 1 week ago.
            {if:else}
                Posted {weeks} weeks ago.
            {/if}
        {if:else}
            I am from the future; I come in peace!
        {/if}
    {/exp:cc_time_difference}
{/exp:channel:entries}
Google+