Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

DateTimeAdd outputting DateTime rather than Date causing unexpected results

SamBealing
6 - Meteoroid

If I run the following formula:

DateTimeAdd(ToDate("2022-12-31"), 0, "years") <= ToDate("2022-12-31")

 

I would expect to get TRUE (since the dates on both sides should be the same). However, running this (in version 2022.1.1.25127), I get FALSE.

 

What seems to be happening is that DateTimeAdd outputs a DateTime rather than a Date and if is Date stored as a Date and is the identical date but stored as a DateTime then y<x.

 

If I wrap the DateTimeAdd in a ToDate:

ToDate(DateTimeAdd(ToDate("2022-12-31"), 0, "years")) <= ToDate("2022-12-31")

 

Then I get TRUE as I would expect.

 

Not sure whether this is enough to classify as a bug (given the easy fix with wrapping in ToDate) but certainly wasn't the behaviour I was expecting and caused me issues when I was trying to check if Date + some number of years is after some other fixed date (as the equality case didn't behave as expected). 

 

2 REPLIES 2
Felipe_Ribeir0
16 - Nebula

Hi @SamBealing 

 

I believe that the problem here is that you are comparing a datetime (that comes from the DateTimeAdd function) with a date (that comes from the ToDate function). If you compare them both as dates or datetimes, you will get the expected result.

 

Felipe_Ribeir0_1-1671549005429.png

 

 

Felipe_Ribeir0_0-1671548990897.png

 

RogerS
Alteryx
Alteryx

you can use a datetime diff to simplify in a single formula.  

RogerS_0-1671564561623.png

 

Labels