Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

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

How do i use DateTimeDiff Formula for

Mostafa_Anwar
8 - Asteroid

i want to use DateTimeDiff Formula for: In case of Department Type = HR and Request submitted date XXX and Approved Date XXXX < 15 Days OR Department Type = MKT and Request submitted date XXX and Approved Date XXXX < 17 Days then Late request Else Normal request

 

Thanks in Advance.

8 REPLIES 8
jdunkerley79
ACE Emeritus
ACE Emeritus

I think you want something like:

 

 

IF ([Department Type] = "HR" AND DateTimeDiff([Approved Date XXXX], [Request submitted date XXX], "days") > 15) 
OR ([Department Type] = "MKT" AND DateTimeDiff([Approved Date XXXX], [Request submitted date XXX], "days") > 17)
"Late"
ELSE
"Normal"
ENDIF

 

The Dates need to be in Alteryx Date or DateTime format (i.e. yyyy-MM-dd or yyyy-MM-dd HH:mm:ss).

DateTimeDiff takes end date first and start date date second. 

You can specify different units like days as the third argument.

 

Hopefully enough to get you going

 

Mostafa_Anwar
8 - Asteroid

Thanks for your respond, i tried to replicate the same provided formula but the attached screenshot error displayed despite all dates values are in Date format. 

 

Date.jpg 

jdunkerley79
ACE Emeritus
ACE Emeritus

Could you post the data?

 

It is trying to convert the value 'Normal' into a date

Mostafa_Anwar
8 - Asteroid

Here you are.

BenMoss
ACE Emeritus
ACE Emeritus

@Mostafa_Anwar your formula tool 68 has the following logic...

 

IF ([Venue Type] = 'Inside HCO' AND DateTimeDiff([EventDate], [SubmittedDate], "days")>=14)
OR ([Venue Type] = 'Outside HCO' AND DateTimeDiff([EventDate], [SubmittedDate], "days")>=30) then 'Late Submisstion' Else 'Normal' endif

Which returns one of two strings, 'Late Submission' or 'Normal', these are string in type, but you have the DateType as 'Date', you need to convert this to a string type.

 

Remember, when creating a field you are specifying the datetype of the result, not the component fields that are being used.

 

Ben

Mostafa_Anwar
8 - Asteroid

Thanks Ben for your respond, Is it possible to change this in my previous dataset shared? because i tired to change it to String but in vain. 

jdunkerley79
ACE Emeritus
ACE Emeritus

Just amend the type in the Formula editor:

2019-01-22_14-00-07.jpg

 

Hopefully should fix it. Tweaked version attached.

Mostafa_Anwar
8 - Asteroid

Thanks Its worked now :)

Truly appreciated.

Labels