Re: [Qgis-user] Calculate age in years with expressionbuilder

2017-12-19 Thread Stefan Giese (WhereGroup)

Hi Reginald,
you should use Year(todate(now()) without the underscore in 
to_date...but don't ask me why...


best
stefan

---
Mit freundlichen Grüßen
Stefan Giese
Projektleiter/Consultant

Das WhereGroup-Team wünscht Ihnen ein frohes
Weihnachtsfest und ein glückliches Jahr 2018!

Die Termine der FOSS Academy für 2018 sind online!
Alle Infos unter www.foss-academy.com


WhereGroup GmbH & Co. KG
Schwimmbadstr. 2
79100 Freiburg
Germany

Fon: +49 (0)761 / 519 102 - 61
Fax: +49 (0)761 / 519 102 - 11

stefan.gi...@wheregroup.com
www.wheregroup.com
Amtsgericht Bonn, HRA 6788
---
Komplementärin:
WhereGroup Verwaltungs GmbH
vertreten durch:
Olaf Knopp, Peter Stamm
---

Am 2017-12-19 09:14, schrieb Reginald Carlier:

Thanks Stefan,

I finally got the age by using this code:

(2017 - year(to_date("GDate")))

Year(to_date(now()) seems to fail as there are missing brackets but I
can't figure out where.

Regards,

Reginald Carlier

Deskundige GIS

 [1]

Gemeente Ingelmunster
,
Oostrozebekestraat 4
,
8770

Ingelmunster

T
+32 51 33 74 39 [2]

WWW.INGELMUNSTER.BE [1]

 [3]
 [4]
 [5]
 [6]

RAADPLEEG ONZE DISCLAIMER  [7]

 -Oorspronkelijk bericht-
Van: Stefan Giese (WhereGroup) [mailto:stefan.gi...@wheregroup.com]
Verzonden: dinsdag 19 december 2017 8:58
Aan: Reginald Carlier
CC: qgis-user@lists.osgeo.org
Onderwerp: Re: [Qgis-user] Calculate age in years with
expressionbuilder

I forgot: and as a workaround you can use:
year(todate(now()) - year(todate("GDate")) which will produce correct
ages, or you can use your own python function (expression
builder->functions->new file):

from qgis.core import *
from qgis.gui import *

from datetime import datetime
from dateutil.relativedelta import relativedelta

@qgsfunction(args=2, group='Python')
def GetAge(values,feature,parent):
'''
call this function GetAge("fromdate","todate")
in years
'''
d1 =datetime.strptime(values[0],"%Y-%m-%d")
d2 =datetime.strptime(values[1],"%Y-%m-%d")
difference = relativedelta(d2, d1)
return difference

Am 2017-12-19 07:48, schrieb Stefan Giese (WhereGroup):

it seems, that this is a bug, see:
https://issues.qgis.org/issues/17681

best regards
Stefan


Am 2017-12-18 15:26, schrieb Reginald:

hello,

I am calculating the age of persons with the expression builder.
My formulae looks like this:
year(age( to_date(now()) , "GDate" )) The result looks alright for
people who are younger than 68 years.
People who are born in 1949 or before get negative ages and the age



goes from -68 to -31 (for someone born in 1913) What is wrong with

my

formulae?

Regards,






--
Sent from:
http://osgeo-org.1560.x6.nabble.com/QGIS-User-f4125267.html
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user



Links:
--
[1] http://www.ingelmunster.be/
[2] tel:+32%2051%2033%2074%2039
[3] https://www.facebook.com/Ingelmunster/
[4] https://www.instagram.com/ingelmunster/
[5] https://www.pinterest.com/ingelmunster/
[6] https://twitter.com/ingelmunster
[7] http://www.ingelmunster.be/email-disclaimer.html

___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Re: [Qgis-user] Calculate age in years with expressionbuilder

2017-12-19 Thread Reginald Carlier
Thanks Stefan,

I finally got the age by using this code:

(2017 - year(to_date("GDate")))

Year(to_date(now()) seems to fail as there are missing brackets but I can't 
figure out where.

Regards,


Reginald Carlier
Deskundige GIS
Gemeente Ingelmunster, Oostrozebekestraat 4, 8770 Ingelmunster
T+32 51 33 74 39www.ingelmunster.be
Raadpleeg onze disclaimer
-Oorspronkelijk bericht-
Van: Stefan Giese (WhereGroup) [mailto:stefan.gi...@wheregroup.com]
Verzonden: dinsdag 19 december 2017 8:58
Aan: Reginald Carlier
CC: qgis-user@lists.osgeo.org
Onderwerp: Re: [Qgis-user] Calculate age in years with expressionbuilder

I forgot: and as a workaround you can use:
year(todate(now()) - year(todate("GDate")) which will produce correct ages, or 
you can use your own python function (expression builder->functions->new file):

from qgis.core import *
from qgis.gui import *

from datetime import datetime
from dateutil.relativedelta import relativedelta

@qgsfunction(args=2, group='Python')
def GetAge(values,feature,parent):
 '''
 call this function GetAge("fromdate","todate")
 in years
 '''
 d1 =datetime.strptime(values[0],"%Y-%m-%d")
 d2 =datetime.strptime(values[1],"%Y-%m-%d")
 difference = relativedelta(d2, d1)
 return difference


Am 2017-12-19 07:48, schrieb Stefan Giese (WhereGroup):
> it seems, that this is a bug, see:
> https://issues.qgis.org/issues/17681
>
> best regards
> Stefan
>
>
> Am 2017-12-18 15:26, schrieb Reginald:
>> hello,
>>
>> I am calculating the age of persons with the expression builder.
>> My formulae looks like this:
>> year(age( to_date(now()) , "GDate" )) The result looks alright for
>> people who are younger than 68 years.
>> People who are born in 1949 or before get negative ages and the age
>> goes from -68 to -31 (for someone born in 1913) What is wrong with my
>> formulae?
>>
>> Regards,
>>
>>
>>
>>
>>
>>
>> --
>> Sent from:
>> http://osgeo-org.1560.x6.nabble.com/QGIS-User-f4125267.html
>> ___
>> Qgis-user mailing list
>> Qgis-user@lists.osgeo.org
>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
> ___
> Qgis-user mailing list
> Qgis-user@lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Re: [Qgis-user] Calculate age in years with expressionbuilder

2017-12-18 Thread Stefan Giese (WhereGroup)

I forgot: and as a workaround you can use:
year(todate(now()) - year(todate("GDate"))
which will produce correct ages, or you can use your own python function 
(expression builder->functions->new file):


from qgis.core import *
from qgis.gui import *

from datetime import datetime
from dateutil.relativedelta import relativedelta

@qgsfunction(args=2, group='Python')
def GetAge(values,feature,parent):
'''
call this function GetAge("fromdate","todate")
in years
'''
d1 =datetime.strptime(values[0],"%Y-%m-%d")
d2 =datetime.strptime(values[1],"%Y-%m-%d")
difference = relativedelta(d2, d1)
return difference


Am 2017-12-19 07:48, schrieb Stefan Giese (WhereGroup):

it seems, that this is a bug, see: https://issues.qgis.org/issues/17681

best regards
Stefan


Am 2017-12-18 15:26, schrieb Reginald:

hello,

I am calculating the age of persons with the expression builder.
My formulae looks like this:
year(age( to_date(now()) , "GDate" ))
The result looks alright for people who are younger than 68 years.
People who are born in 1949 or before get negative ages and the age 
goes

from -68 to -31 (for someone born in 1913)
What is wrong with my formulae?

Regards,






--
Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-User-f4125267.html
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Re: [Qgis-user] Calculate age in years with expressionbuilder

2017-12-18 Thread Stefan Giese (WhereGroup)

it seems, that this is a bug, see: https://issues.qgis.org/issues/17681

best regards
Stefan


Am 2017-12-18 15:26, schrieb Reginald:

hello,

I am calculating the age of persons with the expression builder.
My formulae looks like this:
year(age( to_date(now()) , "GDate" ))
The result looks alright for people who are younger than 68 years.
People who are born in 1949 or before get negative ages and the age 
goes

from -68 to -31 (for someone born in 1913)
What is wrong with my formulae?

Regards,






--
Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-User-f4125267.html
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user