Cognito-forms – Cognito forms – Age at January the First

cognito-forms

Calculating Age in Cognito Forms.

Age in years:

= DateTime.Today.Year - BirthDate.Year + (
if DateTime.Today.Month < BirthDate.Month or 
(DateTime.Today.Month = BirthDate.Month and 
DateTime.Today.Day < BirthDate.Day) then -1 else 0)

This way we can calculate the age today, what about if I need to calculate the age, in years, at January the 1st 2019?

Best Answer

The easiest way for you to this is to simply replace

DateTime.Today

with

DateTime.Parse("1/1/2019")

This calculation would also work, and is less complicated.

=DateTime.Parse("1/1/2019").AddTicks(-BirthDate.Ticks).Year - 1