Hi Karen,
First thank you for making "as time ago" working again.

Some time ago, I found default granularity settings for format_interval either in /includes/common.inc and in the date_api.module, both set to 2. And when I changed it to 1, I got "as time ago" displayed with 1 unit. But, unfortunately, this seems to work no longer. So where can I set this granularity to display only 1 unit now?

Comments

ehr’s picture

I found now a 3rd location, where granularity for "as time ago" is set per default now: In /modules/date/date/date.theme, it is in the function theme_date_time_ago($start_date, $end_date) where date_format_interval($start_date, 2) is called two times with granularity set to 2. Change it to 1 for 1 unit to display.

For better results with 1 unit displayed for "as time ago", you should also change in /includes/common.inc
in function format_interval at line 1219 the format_plural(floor(... to format_plural(round(...

Hope you can understand me, although I'm quite new to drupal, and as far I'm not be able to produce such proper patch format, sometimes cited in issues.
And of course, we all would appreciate a select box for "as time ago"-granularity somewhere, perhaps in CCK or better in the Views module.

dorien’s picture

This would be great. It would provide an "age" display from a birthday field.

ehr’s picture

In this case it should remain floor(...). But if you point to an event i.e. on the overnext day morning, it definitely should be round() to display 2 days rather than 1. So I think, even with 1 unit displayed, not only granularity but this floor() or round() should be selectable too.

citronica’s picture

Thank you! Very helpful :-)

sokrplare’s picture

The date function has been moved into theme/theme.inc

For me, switching the common.inc function to "ceil" instead of "round" gave me what I needed since it was calculating "Days until..."

I'd recommend doing the date theme/theme.inc overwrite in the template.php file so at least there is one less core modification.

See this node for how to do it in template.php (http://drupal.org/node/457740)

barckhoff’s picture

This works for me, but I'm also trying to get the "ago" removed from the display also (because, as someone suggested above, I want to display a person's age). According to the code in theme.inc, this is put there by the format_interval function, but when I looked at the format_interval or theme_date_format_interval functions, I didn't see any reference to adding the text "ago".

If anyone else is looking for this, I finally found it in the date_format_interval() function in date_api.module . Unfortunately, I don't think it's possible to override this in the template.php file.

deggertsen’s picture

Component: Miscellaneous » Date API
Category: support » feature

@barckhoff and @covenantd, thanks for finding that. Too bad that it has to be a core override.

This really is a feature request to allow for setting the granularity for "as time ago" as well as the text that accompanies it. Ideally you would be able to set the granularity and also override the text output so that you could make so that it doesn't have any text. For example: As stated above you may be doing years old and therefore need it set to 1 and the word ago changed to old; you may even want it to simply just show the years ago without any words. There may very well be some other applications that making these changes would allow for.

This would be a great feature to add...

ccrackerjack’s picture

subscribe for feature request.

iparsin’s picture

I wanted to use "As Time Ago" as someone's age as well. After 3 days searching everywhere on web and in Drupal folder, I tried to just get rid of one word. But no luck just like you all said here, there is no corresponding text to "ago" to override, I gave up:( Drupal way is great because most of the features is possibly altered, but not in this case I guess.

Anyone know how-to please help, thanks...
iparsin

vcrkid’s picture

Is there any plans to add this feature?

Some time has passed since the request and there have been releases, but from what I've gathered through trying it out, this feature hasn't been added. :-(

yazzz.b’s picture

I'm also just trying to remove the word "ago." Has anyone figured out how to do this one yet?

d.holmen@gmail.com’s picture

I also need that one removed.

Subscribing

jonathanmd’s picture

Subscribing

Prine’s picture

May not be the optimal solution but this worked for me.

1. Click on Date field in you Fields column
2. Select "time ago" with granularity of 1 (or whatever suits your needs)
3. Open "Rewrite results" and tick "Trim this field to a maximum length"
4. Depending on granularity, count the length of the text (minus the 3 characters for ago) and enter total
5. Tick "Strip HTML tags" (to remove markup for your max length to work properly)

Save.

Like i said not the best, but worked for my needs to display the Age of users in a table without "ago".

Prine’s picture

dp. Sorry.

damienmckenna’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Unfortunately the Drupal 6 version of the Date module is no longer supported. That said, we appreciate that you took time to work on this issue. Should this request still be relevant for Drupal 7 please feel free to reopen it. Thank you.