date field=calculating time

More
11 years 7 months ago #42502 by discrockers
Hello,

is it possible to let the date field calculate the time?

We would like to let the user enter the birthday into the datefield and it would be great if we can display the age.

best regards
J

keep on rockin
J

Please Log in or Create an account to join the conversation.

More
11 years 7 months ago #42511 by ggppdk
Replied by ggppdk on topic date field=calculating time
Hello

you can try something like:
Code:
<?php $field_id = 55; // CHANGE THIS if ( !empty($item->fieldvalues[$field_id]) ) { $nowdate_secs = time(); $fielddate_secs = strtotime($item->fieldvalues[$field_id][0]); $elapsed_secs = $nowdate_secs - $fielddate_secs; echo $elapsed_secs / (60*60*24*365.25); echo " years old <br/>"; } ?>

the above is untested, but will work with minor corrections, (e.g. you may have to change $item with $items[$i])

i guess we can add this capability to the date field

Regards


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
11 years 7 months ago #42518 by discrockers
Hello Mr G. ;)

wow, that was,again(!) a fast answer.

Where do I have to add the code?

Would be a great feature for the datefield.

Thank you very mutch

keep on rockin
J

Please Log in or Create an account to join the conversation.

More
11 years 6 months ago #42532 by ggppdk
Replied by ggppdk on topic date field=calculating time
Hello

you can add it inside item.php or category_items.php of your custom flexicontent template


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
11 years 6 months ago #42534 by discrockers
Hi,

I insert your code inside like this in the item.php of my team template and changed the field ID to the dog birthday field. But, couldn't see an error or a change

<?php
// Modular item layout
// If customizing via CSS rules or JS scripts is not enough, then please copy the following file here to customize the HTML too
include(JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'tmpl_common'.DS.'item_layouts'.DS.'modular.php');


?>

<?php
$field_id = 18; // CHANGE THIS

if ( !empty($items[$i]->fieldvalues[$field_id]) )
{
$nowdate_secs = time();
$fielddate_secs = strtotime($items[$i]->fieldvalues[$field_id][0]);

$elapsed_secs = $nowdate_secs - $fielddate_secs;
echo $elapsed_secs / (60*60*24*365.25);
echo " years old <br/>";
}
?>

keep on rockin
J

Please Log in or Create an account to join the conversation.

More
11 years 6 months ago #42537 by ggppdk
Replied by ggppdk on topic date field=calculating time
Hello

for item view replace (multiple times)
$items[$i]
with
$item

(also $item should work in category view too)


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 2.719 seconds
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline
Save