Alteryx Designer Desktop Discussions

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

Converting String to Date - YYYY only

VizWithDan
7 - Meteor

Hi All,

 

As part of my Alteryx workflow I'm trying to convert a field I have "Year" to a date format to be able to use this in Tableau correctly.

However, I've tried the following and none of these work.

 

Using the formula tool

 

DateTimeFormat(DateTimeParse([kyear],'%Y'),'%Y')

I have also tried the about seperatly and not nested

 

I've also tried using the datetime tool however there is no option for just YYYY

 

The simple question is how do I convert my string to date for just a year format

 

I can run my query successfully however in my Results tab it states that Year (my field) is not a valid date.

 

Any help would be greatly appreciated

 

Thanks

 

DB

3 REPLIES 3
AndrewW
11 - Bolide

A 4 digit year won't be recognised as a date in Alteryx or tableau as it's not a date, once converted to a year it's an integer (or at least should be). Better to use the date functions you've already been using and convert it to a genuine date, for example 01/01/2016.

 

Alternatively you can keep it as a 4 digit integer - the year in other words - and convert it to a date once in Tableau using tableau's MAKEDATE function, where you would also need to add a day and month to make it into a recongisable date.

jdunkerley79
ACE Emeritus
ACE Emeritus

Simplest way is to user a formula tool and a new Date field with formula: 

 

ToString([kyear],0)+'-01-01'

This assumes kyear is stored as an integer. If already a string then no need for ToString.

 

Date in Alteryx are just yyyy-MM-dd strings.

 

Example attached.

VizWithDan
7 - Meteor

Thanks to both of you, these both helped resolve my query

 

DB

Labels