Advent of Code is now back for a limited time only! Complete as many challenges as you can to earn those badges you may have missed in December. Learn more about how to participate here!
Start Free Trial

Alteryx Designer Desktop Discussions

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

Putting together day month and year

J054305
6 - Meteoroid

Hello - I have a {Month} column with numbers  1 through 12 for the month. I have been trying to make a date out of it -- meaning to add a 1 for the day and 2022 for the year. I have tried multiple different ways but keep getting conversion errors - here's the formula i have so far. Any help with this is greatly appreciated!

 

 

datetimeformat("2022-"+PadLeft(ToString([Month]),2,'0')+"-01",'%m-%d-%Y')

 

 

ERROR: ConvError: Select (274): Date: "01-01-2022 00:00:00" is not a valid DateTime

4 REPLIES 4
DataNath
17 - Castor
17 - Castor

Hey @J054305, unless I’m mistaken, the error message looks like it’s coming from a select tool, so the issue isn’t with your formula?

 

There’s no time element in your output so try changing it to just a Date instead of DateTime? If the issue persists then perhaps try using the DateTime tool instead of a select?

Adrian_T
Alteryx Alumni (Retired)

Hi @J054305,

 

The DateTimeFormat function converts a DateTime variable into a string and not the other way around, so you should not be looking at that formula in this case.

 

It would also be worthwhile to keep in mind that Alteryx uses the ISO format yyyy-mm-dd HH:MM:SS to represent dates and times.

 

Using the ToDate() function should solve your issue here: ToDate("2022-"+PadLeft(ToString([Month]),2,'0')+"-01")

 

Hope this helps!

 

image.png

binuacs
21 - Polaris

@J054305 One way of doing this with the DateTimeParse function

DateTimeParse('2022-'+ toString([Month])+'-01','%Y-%m-%d')

binuacs_0-1654893704449.png

 

J054305
6 - Meteoroid

Thank you so much everyone! i was able to get a solution based on your recommendations

Labels
Top Solution Authors