Change elapsed time after a month to different format
<p>I am using codeigniter and I have this code below It converts date in to a elapsed time to something like <code>Asked 1 month, 3 weeks ago</code> </p>

<p>If the date is older than a month I would like it to only display like date <code>Asked Sept 01 05:34:13</code> and  if older than a year <code>Asked Sept 01 2015 05:34:13</code></p>

<p><strong>Currently if time is under month prints out like below which is fine</strong> </p>

<p><strong>example</strong> Asked 1 minute, 14 seconds ago</p>

<p><strong>example</strong> Asked 2 weeks, 3 hours ago</p>

<pre><code>$this-&gt;when_was_question_posted(strtotime('2016-09-01 05:34:13'))
</code></pre>

<blockquote>
  <p>Question how can I make sure that if the date is older than a month
  then display like date <code>Asked Sept 01 05:34:13</code> and if older than a
  year <code>Asked Sept 01 2015 05:34:13</code></p>
</blockquote>

<pre><code>function when_was_question_posted($distant_timestamp, $max_units = 2) {
    $i = 0;
    $time = time() - $distant_timestamp; // to get the time since that moment

    $tokens = [
        31536000 =&gt; 'year',
        2592000 =&gt; 'month',
        604800 =&gt; 'week',
        86400 =&gt; 'day',
        3600 =&gt; 'hour',
        60 =&gt; 'minute',
        1 =&gt; 'second'
    ];

    $responses = [];

    while ($i &lt; $max_units) {
        foreach ($tokens as $unit =&gt; $text) {
            if ($time &lt; $unit) {
                continue;
            }
            $i++;
            $numberOfUnits = floor($time / $unit);

            $responses[] = $numberOfUnits . ' ' . $text . (($numberOfUnits &gt; 1) ? 's' : '');
            $time -= ($unit * $numberOfUnits);
            break;
        }
    }

    if (!empty($responses)) {
        return 'Asked ' . implode(', ', $responses) . ' ago';
    }

    return 'Just now';
}
</code></pre>

<p><a href="https://i.stack.imgur.com/ow0iY.png" rel="nofollow"><img src="https://i.stack.imgur.com/ow0iY.png" alt="enter image description here"></a></p>