user3071261
user3071261

Reputation: 386

Shorten date notation codeigniter

I'm building a webapp with CodeIgniter and I want to show the latest posts. I calculate the time between the date of posting and the current date. The problem is that it shows like this: 1d 4h 2m or 9h 32m. So I actually want only to show the 1d or 9h in this case. How is this possible?

This is how I calculate the time:

span class="time"><?php
                           $this->load->helper('date');

                           $post_date = strtotime($t['story_date']);
                           $now = strtotime(date('Y-m-d H:i:s'));

                           echo timespan($post_date, $now);

                           ?> </span>

Upvotes: 0

Views: 61

Answers (1)

Atural
Atural

Reputation: 5439

There is a 3rd Parameter called "Units" for the timespan function - maybe is this helpful ? Look here for more information

Upvotes: 1

Related Questions