How do I round down for age date calculation?

  • 30 October 2014
  • 4 replies
  • 8 views

Userlevel 4
Badge +12

Hi I'm trying to calculate age in years from a date of birth date field.

 

I've seen the old connect post

Nintex Connect - Need to calculate age of patient based off of birthdate

Which uses dateDiffDays(DOB,Current Date)/365

 

The problem is that this gives a decimal number and not an integer.

If I use the round function it will also round up in some cases

eg 7.78 would be come 8 when in fact they are still 7 years old.

 

Any ideas on how to solve this?

 

I did some playing around in Excel that has some other functions such as YEARFRAC and ROUNDDOWN which produce a more accurate result.

However feeling a bit limited with the runtime functions available.

 

Thanks


4 replies

Badge +11

I agree with Martin S.

Userlevel 4
Badge +12

Thanks Martin.

I was thinking about convert to string, strip the period and all chars after it.

Then convert back to integer.

Just hoping there was a better.

I think I'm heading over to uservoice to request some additional functions.

[I need a button for 'good enough' answer rather than correct answer] happy.png

Userlevel 6
Badge +12

If you have workflow enterprise edition, another way you could perform this is by using Excel.  You'd have an Excel spreadsheet stored somewhere with the two dates and a formula written exactly how you want it (using rounddown / yearfrac etc) and then use the Query Excel Services action.

With this action you can supply the two dates and take the answer from the cell that has the formula in it.

Cheers,

Chris

Userlevel 6
Badge +12

Ooops.  Before everyone replies back, I just realised you were asking this from a forms perspective, not a workflow perspective.  You will be able to do this via Forms Enterprise Edition except you'll have to use the new call webservice action instead ;-)

Reply