How to retrieve the number of years, months, or days between two dates in DataWeave 2.0

Updated: Sep 4

The video version of this article can be found at the end of the post.



I was working on a pretty fun API for some demo purposes, and I needed to get a person’s age. Of course, my first instinct was to jump right into it and start using different core functions. (By the way, if you haven’t seen my DataWeave 2.0 core functions cheat sheet, check it out here!)


I started using “daysBetween”, and then I manually counted the days to convert them to years. You know, like, 365 days equals a year, so divide all the days in between...You know what? It’s not even worth explaining how I got to a wrong answer.


In this post, I’ll show you how to use the “between” function from the Periods module (which I can