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

Comparing Dates with DateTimeTrim

ryeldell
5 - Atom

I didn't find a post on this, but I was getting unexpected results in a formula where I was testing a date with the results of the DateTimeTrim function. It was resolving to false even thought the "date part" of the DateTimeTrim was the same as the date.

 

Try a simple formula like below and the boolean result is false.

 

"2016-01-01"=DateTimeTrim("2016-01-01","month")

7 REPLIES 7
MarqueeCrew
20 - Arcturus
20 - Arcturus

DateTimeTrim("2016-10-23","month") =

DateTimeTrim("2016-10-31","month")

 

that will yield true 

 

I suppose that

 

"2016-10"=

DateTimeTrim("2016-10-31","month")

 

will also yield true. 

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
jdunkerley79
ACE Emeritus
ACE Emeritus

Alteryx treats Dates and DateTimes as strings. DateTimeTrim returns the value as a datetime string (i.e. with a trailing 00:00:00) so DateTimeTrim("2016-10-31","month") becomes "2016-10-01 00:00:00".

 

The easiest way I find to do a month comparison is:

LEFT("2016-10-31",7) == LEFT("2016-10-23", 7)

 

jdunkerley79
ACE Emeritus
ACE Emeritus
 
ryeldell
5 - Atom

Very nice. I didn't know that they were treated as strings.

 

Can you change "lfet" to "left"? Then I can mark it as answered. Thanks again!

MarqueeCrew
20 - Arcturus
20 - Arcturus

I think that it is safe to mark this as solved :P


Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
jdunkerley79
ACE Emeritus
ACE Emeritus

Fixed :)

F5_GL
6 - Meteoroid

I know that this post is old but I found that I search for Date Time function help the most.

 

Nice to know that DateTimeTrim("2016-10-31",'month') works like DateTimeTrim("2016-10-31",'firstofmonth')

 

I was also able to get DateTimeTrim("2016-10-31",'day') to work also

Labels