<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii" /></head><body><div>Thanks Stefan,<br /><br />I finally got the age by using this code:<br /><br />(2017 - year(to_date("GDate")))<br /><br />Year(to_date(now()) seems to fail as there are missing brackets but I can't figure out where.<br /><br />Regards,<br /><br /><div style="mso-line-height-rule:exactly;-webkit-text-size-adjust:100%;white-space:nowrap;"><table cellpadding="0" cellspacing="0" border="0" style="width:100%;font-size:0;"><tr><td align="left" style="vertical-align:top;"><table cellpadding="0" cellspacing="0" border="0" style="width:100%;font-size:0;"><tr><td align="left" style="padding:5px 0;vertical-align:top;"><table cellpadding="0" cellspacing="0" border="0" style="width:100%;font-size:0;"><tr><td align="left" style="vertical-align:top;"><table cellpadding="0" cellspacing="0" border="0" style="font-size:14.67px;color:#5C676D;font-style:normal;font-weight:400;"><tr><td align="left" style="padding:2px 0;vertical-align:top;font-family:Tahoma;">Reginald Carlier</td></tr></table></td></tr><tr><td align="left" style="vertical-align:top;"><table cellpadding="0" cellspacing="0" border="0" style="font-size:13.33px;color:#5C676D;font-style:normal;font-weight:400;"><tr><td align="left" style="padding:2px 0;vertical-align:top;font-family:Tahoma;">Deskundige GIS</td></tr></table></td></tr></table></td></tr></table></td></tr><tr><td align="left" style="vertical-align:top;"><table cellpadding="0" cellspacing="0" border="0" style="font-size:0;line-height:normal;"><tr><td align="left" style="padding:3px 0;vertical-align:top;"><a href="http://www.ingelmunster.be/" target="_blank" id="LPlnk689713" style="text-decoration:none;"><img src="http://www.ingelmunster.be/ingelmunster.gif" height="65" border="0" alt="" style="height:65px;min-height:65px;max-height:65px;font-size:0;" /></a></td></tr></table></td></tr><tr><td align="left" style="vertical-align:top;"><table cellpadding="0" cellspacing="0" border="0" style="font-size:0;"><tr><td align="left" style="padding:2px 0;vertical-align:top;"><table cellpadding="0" cellspacing="0" border="0" style="font-size:12px;color:#5C676D;font-style:normal;font-weight:400;"><tr><td align="left" style="vertical-align:top;font-family:Tahoma;">Gemeente Ingelmunster</td><td align="left" style="vertical-align:top;font-family:Tahoma;">, </td><td align="left" style="vertical-align:top;font-family:Tahoma;">Oostrozebekestraat 4</td><td align="left" style="vertical-align:top;font-family:Tahoma;">, </td><td align="left" style="vertical-align:top;font-family:Tahoma;">8770</td><td align="left" style="vertical-align:top;font-family:Tahoma;"> </td><td align="left" style="vertical-align:top;font-family:Tahoma;">Ingelmunster</td></tr></table></td></tr></table></td></tr><tr><td align="left" style="vertical-align:top;"><table cellpadding="0" cellspacing="0" border="0" style="font-size:0;"><tr><td align="left" style="padding:2px 0;vertical-align:top;"><table cellpadding="0" cellspacing="0" border="0" style="font-size:12px;color:#5C676D;font-style:normal;font-weight:400;"><tr><td align="left" style="vertical-align:top;font-family:Tahoma;">T</td><td align="left" style="vertical-align:top;font-family:Tahoma;"><a href="tel:+32%2051%2033%2074%2039" target="_blank" id="LPlnk689713" style="text-decoration:none;color:#5C676D;"><strong style="font-weight:400;">+32 51 33 74 39</strong></a></td><td align="left" style="vertical-align:top;font-size:0;"><table cellpadding="0" cellspacing="0" border="0" style="font-size:12px;color:#5C676D;font-style:normal;font-weight:400;"><tr><td align="left" style="padding:0 0 0 5px;vertical-align:top;font-family:Tahoma;"><a href="http://www.ingelmunster.be/" target="_blank" id="LPlnk689713" title="Website Ingelmunster" style="text-decoration:none;color:#5C676D;"><strong style="font-weight:400;">www.ingelmunster.be</strong></a></td></tr></table></td></tr></table></td></tr></table></td></tr><tr><td align="left" style="vertical-align:top;"><table cellpadding="0" cellspacing="0" border="0" style="font-size:0;"><tr><td align="left" style="padding:4px 0 2px;vertical-align:top;"><table cellpadding="0" cellspacing="0" border="0" style="font-size:0;line-height:normal;"><tr><td align="left" style="vertical-align:top;"><a href="https://www.facebook.com/Ingelmunster/" target="_blank" id="LPlnk689713" style="text-decoration:none;"><img src="http://www.ingelmunster.be/fb.jpg" height="19" border="0" title="Facebook" alt="Facebook" style="height:19px;min-height:19px;max-height:19px;font-size:12px;" /></a></td><td align="left" style="vertical-align:top;"><a href="https://www.instagram.com/ingelmunster/" target="_blank" id="LPlnk689713" style="text-decoration:none;"><img src="http://www.ingelmunster.be/in.jpg" height="19" border="0" title="instagram" alt="instagram" style="height:19px;min-height:19px;max-height:19px;font-size:12px;" /></a></td><td align="left" style="vertical-align:top;"><a href="https://www.pinterest.com/ingelmunster/" target="_blank" id="LPlnk689713" style="text-decoration:none;"><img src="http://www.ingelmunster.be/pi.jpg" height="19" border="0" title="pinterest" alt="pinterest" style="height:19px;min-height:19px;max-height:19px;font-size:12px;" /></a></td><td align="left" style="vertical-align:top;"><a href="https://twitter.com/ingelmunster" target="_blank" id="LPlnk689713" style="text-decoration:none;"><img src="http://www.ingelmunster.be/tw.jpg" height="19" border="0" title="twitter" alt="twitter" style="height:19px;min-height:19px;max-height:19px;font-size:12px;" /></a></td></tr></table></td></tr></table></td></tr><tr style="color:#000001;font-size:9px;font-style:normal;font-weight:400;"><td align="left" style="vertical-align:top;font-family:Tahoma;"><a href="http://www.ingelmunster.be/email-disclaimer.html" target="_blank" id="LPlnk689713" title="disclaimer" style="text-decoration:none;color:#5C676D;"><strong style="font-weight:400;">Raadpleeg onze disclaimer </strong></a></td></tr></table></div><span style="font-family:remialcxesans;"> </span>-----Oorspronkelijk bericht-----<br />Van: Stefan Giese (WhereGroup) [mailto:stefan.giese@wheregroup.com] <br />Verzonden: dinsdag 19 december 2017 8:58<br />Aan: Reginald Carlier<br />CC: qgis-user@lists.osgeo.org<br />Onderwerp: Re: [Qgis-user] Calculate age in years with expressionbuilder<br /><br />I forgot: and as a workaround you can use:<br />year(todate(now()) - year(todate("GDate")) which will produce correct ages, or you can use your own python function (expression builder->functions->new file):<br /><br />from qgis.core import *<br />from qgis.gui import *<br /><br />from datetime import datetime<br />from dateutil.relativedelta import relativedelta<br /><br />@qgsfunction(args=2, group='Python')<br />def GetAge(values,feature,parent):<br />     '''<br />     call this function GetAge("fromdate","todate")<br />     in years<br />     '''<br />     d1 =datetime.strptime(values[0],"%Y-%m-%d")<br />     d2 =datetime.strptime(values[1],"%Y-%m-%d")<br />     difference = relativedelta(d2, d1)<br />     return difference<br /><br /><br />Am 2017-12-19 07:48, schrieb Stefan Giese (WhereGroup):<br />> it seems, that this is a bug, see: <br />> https://issues.qgis.org/issues/17681<br />> <br />> best regards<br />> Stefan<br />> <br />> <br />> Am 2017-12-18 15:26, schrieb Reginald:<br />>> hello,<br />>> <br />>> I am calculating the age of persons with the expression builder.<br />>> My formulae looks like this:<br />>> year(age( to_date(now()) , "GDate" )) The result looks alright for <br />>> people who are younger than 68 years.<br />>> People who are born in 1949 or before get negative ages and the age <br />>> goes from -68 to -31 (for someone born in 1913) What is wrong with my <br />>> formulae?<br />>> <br />>> Regards,<br />>> <br />>> <br />>> <br />>> <br />>> <br />>> <br />>> --<br />>> Sent from: <br />>> http://osgeo-org.1560.x6.nabble.com/QGIS-User-f4125267.html<br />>> _______________________________________________<br />>> Qgis-user mailing list<br />>> Qgis-user@lists.osgeo.org<br />>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user<br />>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user<br />> _______________________________________________<br />> Qgis-user mailing list<br />> Qgis-user@lists.osgeo.org<br />> List info: https://lists.osgeo.org/mailman/listinfo/qgis-user<br />> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user<br /></div></body></html>