Alteryx Designer Desktop Discussions

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

Add Time

Chukwuma
6 - Meteoroid

how do i go about adding 2 fields together one has a DateTime data type (i.e - 2020-05-11 10:04:52) and the other field is a v_Wstring (i.e 01:14:26}. i get an error when i try to use the datetimeadd formula. Thanks 

4 REPLIES 4
mbarone
16 - Nebula
16 - Nebula

Hi @Chukwuma,

 

The DateTimeAdd function takes a date, adds a specified integer to it, and you specify "what" that integer is.

 

In your example, I would first isolate each of the time parts (so hour, minute, seconds).  Then use them to calc total seconds.  Then add the total seconds to your datetime.  See attached for step-by-step.

Jonathan-Sherman
15 - Aurora
15 - Aurora

Hi @Chukwuma,

 

You could use the DateTimeDiff() formula to convert the time to seconds and add it to your first datetime value:

 

DateTimeAdd([DateTimeValue],DateTimeDiff('2000-01-01 ' + [TimeValue],'2000-01-01','seconds'),'seconds')

 

 

If this solves your issue please mark the answer as correct, if not let me know! I've attached my workflow for you to download if needed.

 

Regards,

Jonathan

jdunkerley79
ACE Emeritus
ACE Emeritus

I suggest:

DateTimeAdd(
    [Date],
    DateTimeDiff("1900-01-01 " + [Time], "1900-01-01","seconds"),
    "seconds")

 

This works out the time difference in seconds then adds it to the date.

 

It will fail if time > 24 hours. 

 

Attached a sample

mbarone
16 - Nebula
16 - Nebula

Nice one @jdunkerley79 !!!  Would've never thought of that!

Labels