Alteryx Designer Discussions

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

Add the time to a date field

oracleoftemple
9 - Comet

This one should be pretty easy, but I can't quite find the right response already in a Community discussion.  I have two fields.  One is a DateTime format with zeroes for hours, minutes and seconds, e.g. 2021-04-25 00:00:00.  The other field is a Time format with hours, minutes, and seconds, e.g., 19:11:10.  I just want to add the hours, minutes and seconds in the Time field to the DateTime fields so I end up with 2021-04-25 19:11:10.  Thanks for the assist!!!

2 REPLIES 2
apathetichell
17 - Castor

probably an easier way but try this:

 

datetimeparse(datetimeformat(tostring([mydatefield]),"%Y-%m-%d")+tostring([my time field]),"%Y-%m-%d%H:%M:%S")

 

included an extra "%" after the M so corrected above and here (slightly different field names below)

datetimeparse(datetimeformat(tostring([date]),"%Y-%m-%d")+ tostring([time]),"%Y-%m-%d%H:%M:%S")

 

and one more:

ToDateTime(tostring([date])+" "+tostring([time]))

 

I know that looks easier... but that's only if you remember to include the space in between the date and the time...

atcodedog05
22 - Nova
22 - Nova

Hi @oracleoftemple 

 

Here is a formula on how you can do it.

datetimeparse(datetimeformat([Date],"%Y-%m-%d")+ [time],"%Y-%m-%d%H:%M:%S")

 

Workflow:

atcodedog05_1-1622743967487.png

 

 

datetimeparse(

   datetimeformat([Date],"%Y-%m-%d")            // Taking only date from datetime format

  + [time]                                                           // Concating time value

,"%Y-%m-%d%H:%M:%S")                            // Converting it to datetime

 

Hope this helps 🙂

Labels