Xplan Xmerge Code – Datediff

Xplan Quick Xplain

Datediff: difference between dates made easy

datediff()

A quick but handy function to keep in mind for dates…date coding

In our date coding article one of the things we looked at was how you can calculate the difference between two date periods.  Usually we might need to do this for fact finds, advice documents and coded application forms, common examples include:

  • Calculate retirement ages or age at retirement;
  • Calculate difference between x age and y legislative age;
  • Exclude or include residence and employment based on x years (application forms)

Datediff() makes the calculations simpler

Datediff (Date difference) takes two date objects and works out the difference in years, months and days between the two:

<:=datediff(x, y).z:>

x = Date item 1

y = Date item 2

z = .years or .month or .day

Because of the reverse countdown aspect of it, .years will be the main measure to use.  Some examples of its use:

Years till retirement: <:=datediff($client.retire_date, datetime_merge).years:>

# 25

Retirement age: <:=datediff($client.retire_date, $client.dob).years:>

# 60

Note:  Sometimes its handy to know work arounds because automated functions in xplan can go wrong. For example the retirement age shown on screen in 2.14.14 versions is +1 year off.  If we were using an automated function to get the retirement age (similar to $client.age) our documents would be wrong until IRESS patches this.  Clients don’t or can’t always wait for that to happen, particularly on large sites were even small versions go through internal testing  so knowing alternative methods of getting the data can be invaluable.

Time at current residence:

<:if int(datediff($client.date_moved_in, datetime_merge).years) <3:>
Please provide details of previous residency
<:end:>

Keep in mind:

  • Datediff works on a reverse countdown so if you were working out the points between 2 dates eg (01/01/1980 and 01/01/2015) the result returned would be 3 years, 0 months 0 days.
  • Datediff runs of years, months, days note the plural of the s this is in contrast to when we’re dealing with a single date and to get the individual values its datetime_merge.year etc.
Matthew Townsend
Xplan Consultant and Developer | Wealth Management Technologist at Create Something
Matthew is an experienced and innovative Xplan consultant and developer, having worked on and developed some of the largest advice projects in the industry. Passionate about building great experiences in xplan that enable businesses and clients to get the most out of this powerful software.

Matthew Townsend

Matthew is an experienced and innovative Xplan consultant and developer, having worked on and developed some of the largest advice projects in the industry. Passionate about building great experiences in xplan that enable businesses and clients to get the most out of this powerful software.

Leave a Reply

Your email address will not be published. Required fields are marked *