In case you missed the announcement: Alteryx One is here, and so is the Spring Release! Learn more about these new and exciting releases here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Getting Year and Month difference in alteryx

sahelmajid
5 - Atom

Hi team,

 

I have been trying to get year and month difference between two dates. It is possible in excel through datedif() function. However, I am unable to get the same on alteryx. Below is the example:

 

sahelmajid_0-1659963075915.png

 

Any help would be highly appreciated!

7 REPLIES 7
IraWatt
17 - Castor
17 - Castor

Hey @sahelmajid,

Alteryx is optimised to only allow date calculations with date data types. There is a good quick video on data types on the community here: Understanding Data Types - Alteryx Community. To convert your text to date data types I use the date time tool then a formula to calculate the difference and format the values:

 

IraWatt_0-1659963779243.png

The community has some quick and easy videos on formulas and the Formula Tool here https://community.alteryx.com/t5/Interactive-Lessons/tkb-p/interactive-lessons/label-name/Writing%20...

 

Any questions or issues please ask

Ira Watt
Technical Consultant
Watt@Bulien.com 

 

binuacs
21 - Polaris

@sahelmajid Another way of doing this with the DateTime functions

 

binuacs_0-1659965036441.png

 

sahelmajid
5 - Atom

Thank you so much! That helps. Just curious, what if we want to add days to it as well? 

Can we do that as well with alteryx workflow?

 

sahelmajid_0-1660051478101.png

 

IraWatt
17 - Castor
17 - Castor

@sahelmajid that is an interesting one, I haven't been able to figure out how to add leap days into the calculation which I assume is what is throwing off the number of days:

IraWatt_0-1660054011754.png

 

DataNath
17 - Castor
17 - Castor

Always find these fun and was definitely a little trickier than I first anticipated so decided to have a little stab! If there's any issues when you try applying this to a larger dataset then let me know and I can revisit the logic.

 

DataNath_0-1660056950898.png

 

Obviously you can trim out the actual Years/Month/Days fields with a Select tool afterwards if you don't want them hanging around, or can even compress all of the expressions into one if you don't mind playing around and ending up with a single, mammoth statement.

sahelmajid
5 - Atom

@IraWatt @DataNath Thank you so much for your help! Both of these workflows run perfect even on large datasets.

IraWatt
17 - Castor
17 - Castor

Great to hear @sahelmajid ! Make sure to leave a green tick on replies which solve your problem. Have a great week ðŸ˜„

Labels
Top Solution Authors