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.
SOLVED

Date as String - How to convert to Date

brendafos
10 - Fireball

I've spent some time reading other posts but I've not quite gotten the answer I need.....

 

The incoming data has a field type v_string which looks like 5/8/2015 -- I need to convert this to a type date.

 

I tried the Select tool changing v_string to date but that just outputs 'null's.

 

I tried -

DateTimeParse(
  REGEX_Replace([Text], "([a-z]{3})\s*([0-9]{1}),","$1 0$2,"),
  "%b %d,%Y")

But that gives 'null' and does not give an error.

 

string to date type.png

 

Can I use DateTimeParse with a string type?

Or how is the best way to approach this? 

11 REPLIES 11
jdunkerley79
ACE Emeritus
ACE Emeritus

You need a leading zero on the day as well try:

DateTimeParse(
  RIGHT("0" + REGEX_Replace([Text], "([a-z]{3})\s*([0-9]{1}),","$1 0$2,"), 10),
  "%b %d,%Y")
brendafos
10 - Fireball

And... I already tried to use the Parse - DateTime conversion tool.

but it seems to do nothing - I put a Select after and it still show data type as v_string

NickJ
Alteryx Alumni (Retired)

Hi there, 

 

Attached is a tiny workflow that takes a 'date' as a V_String and uses DateTimeParse to convert to a 'real' date (liberties taken on whether the month is May or August!)

 

Hope this helps?

 

Cheers,

Nick

- Solutions Engineer

Nick Jewell | datacurious.ai
JohnJPS
15 - Aurora

The following worked OK for me:

 

DateTimeParse([dt],"%m/%d/%Y")

 

 

Tested successfull on:

  • 1/1/2001
  • 1/11/2001
  • 11/1/2001
  • 11/11/2001

 

s_pichaipillai
12 - Quasar

@brendafos

 

try DateTimeparse([Field1],'%m/%d/%Y') using formula tool

brendafos
10 - Fireball

Thank you.

I tried you addition... but I still just get nulls

string to date type v2.png

NickJ
Alteryx Alumni (Retired)

Just noticed that you're using the DateTime mask %b (which is lowercase three-letter month name rather than a numeric month) - can you replace this with %m to see if it helps?

 

(Also - can you definitely confirm the format of the incoming V_String? Paste an example if possible?)

 

Cheers,

Nick

- Solutions Engineer

Nick Jewell | datacurious.ai
brendafos
10 - Fireball

NickJ and everyone.-  I am making progress.

 

I at least have a date now  -

 

Here's what I'm using..

DateTimeParse([Enc - Discharge Date],"%m/%d/%Y")

 

But I get an odd format of the output.. the new date column is Enc - Desc Date

Why is it YYYY-MM-DD ?

 

date convert.png

jdunkerley79
ACE Emeritus
ACE Emeritus

That is how Alteryx represents dates, as a string in yyyy-MM-dd format.

 

All the datetime functions operate on this

Labels