Closed wondie closed 6 years ago
I tried to calculate age using the following expression: now() - “date_of_birth”
However, when I try to click the expression button in the editor form, nothing happens.
On Fri, 27 Jul 2018 at 04:32, Wondimagegn Tesfaye notifications@github.com wrote:
Closed #343 https://github.com/gltn/stdm/issues/343.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/gltn/stdm/issues/343#event-1756323424, or mute the thread https://github.com/notifications/unsubscribe-auth/ADqZC7abhWvD0j5moqnDna-zLSSR4zHZks5uKm3DgaJpZM4Vix5H .
-- John Gitau
@gkahiu the QgsExpression only works on a saved features. So it will be only visible after you save the form . After saving if you see the records in the Entity Browser table, you will see it.
I thought so too but even after saving, re-opening and saving again, nothing happened.
Could you send me the configuration?
I used the Rural Agriculture - just added an 'age' column to the Farmer entity. See the configuration in the attached ZIP file.
The problem was the expression. now() is not a date but date and time. "date_of_birth" column is a python date. They both needs to be converted to_date() so that both are QDate. It works with this code.
year(to_date(now()) - to_date("date_of_birth"))
Alright cool, let me give it a try.
This refers to QGIS Expression Builder based column type. This column type is now added. To make use of it, you need to create new columns type called Expression.
This column type helps you do any further calculations using other column values. Some examples of its uses are listed below.
You can read more about it in QGIS documentation;
You can get the entity columns under "Fields and Values" in the second box. Once saved, the recently used expressions are saved and stored under "Recent" node.
The expression values are saved to the database after saving the feature. The expression is saved by an Update operation that happens soon after adding or editing other attributes.
The supported database columns are integer, decimal, and string.