10 years ago
Topic
Hello,

I would like to show automatically the old of people on my form.

I had a field text with : today
A second field with the calendar that show the date of birthday of people.

I don't find the correct term to show exact old of person. I had installed plugin datetime but it don't work..

Thank you for your help.
Get a VIP membership
10 years ago
2
Level 1
Hello manu74,

you have a textfield with the current date (today)???? I wonder how you get the current date automatically into a text field. I have been searching for a while to get the current date into a field, but I dont find a solution.
In the case you fill in the current date manually - it doesnt make any sense to me.
I guess you want to achieve that the age would be calculated and displayed automatically if a user fills in his birthdate - right?
The plugin datetime only works at the first saving of an article (unfortunately). The date will be stored in the database and if you edit the article the date stays the same.
Maybe you could explain me how you deal with this textfield

Best regards Jürgen
10 years ago
1
Level 2
@Jürgen

it is actually very easy to get the actual date.

In your content or intro view tab, put in a field and set the live value to Default and in the right box type in "now".

You can see a screenshot in the German Seblod forum here.
Gerhard
10 years ago
0
Level 3
Hello Gerhard,

Thanks for the tipp. I`ve been using Seblod since the first version, but I have never seen this option. SEBLOD, what a miracle :-)

Vielen Dank

Jürgen
10 years ago
0
Level 1
Hello,

Sorry Jurgen for my late reply...
Gebeer told you very well for the field today.

And when user complete the field : birthday, it appears the field 'age'
But the value is incorrect, I can not calculate the age...

If you have an idea...
10 years ago
4
Level 1
@manu74

can you please explain more in detail.

What are the date format settings for the birthday field and for the now date field?

Are you calculating with the Seblod computation feature or in a custom position override?

What is the formula you are using to calculate the age from now date and birthday date?

How do you save the birthday date field, datetime or timestamp?


I found this  calculation code in PHP here:

// Takes dates like 'yyyy-mm-dd'

function getAge($birth, $now = NULL)

{

    $now = new DateTime($now);

    $birth = new DateTime($birth);



    return $birth->diff($now)->format('%r%y');

}

10 years ago
0
Level 2
This is exactly on reason to use custom templates. I havent ever used the computation function in SEBLOD, because I always write such calculations via PHP into my custom templates and I always get what I want.
As posted many times in the forum: it seems that there were many problems due to computation rules in SEBLOD.
10 years ago
2
Level 2
Gebeer,



What are the date format settings for the birthday field and for the now date field?
Date format is : datetime for my both field : Today and date of birth.
These fields are Calendar field.

Are you calculating with the Seblod computation feature or in a custom position override?
The response is in the text field named : old.
I use the Seblod computation.

What is the formula you are using to calculate the age from now date and birthday date?
I use the #5 for the field old and I do also : a - b (today - date of birth)

How do you save the birthday date field, datetime or timestamp?
I don't know where I set datetime in this field. Just set dynamic : date & hour in #2



I think it's better to use your code with a new field called age with type 42 but I don't understand how I can use it...
10 years ago
1
Level 3
@manu74

By date format I mean the Output Format like Y-m-d. You can see the setting I am talking about here in the Field "Format".
By format of saving the field I mean the "Storage Format" that you can set. Either Datetime or Timestamp. If you use the values from the DB to do your calculations your custom PHP calculation code will have to be be different, depending on the storage format.

You cannot use the Seblod computation feature to calculate the age. Because age calculation is more complex than just building the difference like a-b.

You will have to use PHP to do this.

I don't know much about the 42 field but I would recommend the Code Pack plugin for your use case. If you don't want to spend money, use a position override or custom template and do the calculation in there.




10 years ago
0
Level 4
Ok, thanks Gebeer, 
I think I will take the Code Pack plugin, I have yet a little list of plugins to purchase.
With this one, it will be more clear and more simple.
See you later.
Get a Book for SEBLOD