Гость
24 Дек 2012 20:35

Can i use Cobalt 8 Date fields create a length of time,for example, the working years of a doctor will change with the time going on year by year,at 2012 the date field show 20years,but at 2013,it will show 21years automatically

Последние изменения: 02 Март 2014


Sackgesicht VIP
Total posts: 1,636
24 Дек 2012 22:14

Yes you can do this with the integrated "output template". You can compute the time (in years) based on the entry date and the time the user visits the page.


Sackgesicht VIP
Total posts: 1,636
25 Дек 2012 18:49

You can create an output template like this:

<?php

defined('_JEXEC') or die() ;

$now = new DateTime(NULL) ;

$age = new DateTime(implode($this->value) ) ;

echo $age->diff($now)->format('%r%y') ;?>

which will display the age (Number of years).

Just save it under the /components/com_cobalt/fields/datetime/tmpl/output/age.php and select it in the fields parameter.

Maybe MintJoomla might consider to enhance the display mode parameter with an option "Years".


pepperstreet VIP
Total posts: 3,837
27 Янв 2013 16:06

Since everything is heading towards jQuery... here is a related plugin. I think, i have seen it before in CommunityBuilder and CB Activity stream, too. Might be of interest for some people:

**timeago

** homepage

"Timeago is a jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago") from ISO 8601 formatted dates and times embedded in your HTML (à la microformats)"

GitHub project page


Jeff VIP
Total posts: 745
09 Май 2013 01:55

"Timeago is a jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago") from ISO 8601 formatted dates and times embedded in your HTML (à la microformats)"

Have you already tried to implement this?


Jeff VIP
Total posts: 745
09 Май 2013 05:55

If I just knew the proper php code to convert Cobalt dates into ISO 8601 formatted dates, then I could use this script right away...:)


Jeff VIP
Total posts: 745
09 Май 2013 07:14

Google and Sergey are your friends ;-)

Yes I know. :)

Google and Sergey are your friends ;-)

Did you try Stackoverflow.com ?

Yes, among others...I'm sure I will come up with something. Not sure if it will be the most efficient piece of php though...:)

Работает на Cobalt