In case you missed the announcement: The Alteryx One Fall Release is here! Learn more about the new features and capabilities here
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests Early 2026. Make sure to check your account preferences in my.alteryx.com to make sure you have filled out your security questions. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

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

Nested IF Date format problem.

Aleksander_Gorski
7 - Meteor

Hi All,

 

I have a problem in handling Nested If statement and I don't understand why is not working.

I am afraid that problem occurs because of date format.

Could you please help me with this?

1 REPLY 1
LukeM
Alteryx Alumni (Retired)

Hi @Aleksander_Gorski,

 

I have fixed your IF statement and the workflow is attached. You have to be careful when dealing with dates in Alteryx as they have to be in a certain format and you must use the functions available in the formula tool to manipulate the data in the way you need. A few key things to note:

  • DateTimeParse(<date>,<format>) - you need to use this to inform Alteryx that the string value "01-01-2019" needs to be treated as a date and what the particular date format is. Check here for Date Format syntax.
  • DateTimeDiff(dt1,dt2,'years') - to find the difference between dates.
  • In an IF statement, you shouldn't refer to the field - it should read 'THEN 5' not 'THEN [FieldName] = 5'

 

If [End date] < DateTimeParse("01-01-2019",'%d-%m-%Y')
Then 5
        
ElseIf [End date] = "" 
Then
        5
    
ElseIf [End date] > DateTimeParse("01-01-2119",'%d-%m-%Y')
Then
         5
        
Else
        
	If [Start Date] > DateTimeParse("01-01-2019",'%d-%m-%Y') 
	Then
        
	DateTimeDiff([End date],[Start Date],'years')
        
	Else
        
	DateTimeDiff([End date], DateTimeParse("01-01-2019",'%d-%m-%Y'),'years')

	EndIf

EndIf

 

Hope this helps. Please refer to to the help documentation - https://help.alteryx.com/current/Reference/Functions.htm?Highlight=datetimeformat - if you need some more information on some of these DateTime functions. Let us know if you have any more questions or need any more help.

 

Best,

 

Luke 

 

Labels
Top Solution Authors