Alteryx Designer Desktop Discussions

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

Date Time conversion

Alteryx_Geek
8 - Asteroid

How do I achieve the below output for Date Time format

 

2021-05-12 14:07:04.441932 = 14:07:04  (when decimal is < 0.5 msec then same digit in second)
2021-05-12 14:07:04.847982 = 14:07:05  (When decimal is >= 0.5 msec then next digit in second

 

Thanks

10 REPLIES 10
Amol_Telore
11 - Bolide

Hey @Alteryx_Geek 

 

Here is my solution. 

  1. Take out second and mili-second part from string.
  2. Round Second number to the nearest integer.
  3. Merge second part with remaining date time string.
  4. convert string to date time using date time parse function.

Amol_Telore_0-1658940217226.png

 

 

 

Regards,

Amol Telore

binuacs
20 - Arcturus

@Alteryx_Geek one way of doing this

 

binuacs_0-1658939968474.png

 

Alteryx_Geek
8 - Asteroid

@binuacs 

 

ConvError: Formula (67): DATETIMEPARSE: Cannot convert "2021-05-12 14:07:60" to a date/time with format "%Y-%m-%d %H:%M:%S": Second is out of range 0..59: '60'
ConvError: Formula (67): DATETIMEPARSE: Cannot convert "2021-05-12 14:07:60" to a date/time with format "%Y-%m-%d %H:%M:%S": Second is out of range 0..59: '60'

 

looks like its working, but then in above scenarios its not working as expected. Instead of giving 14:08:00, it gives as 14:07:60

Alteryx_Geek
8 - Asteroid

@Amol_Telore - 

ConvError: Formula (67): DATETIMEPARSE: Cannot convert "2021-05-12 14:07:60" to a date/time with format "%Y-%m-%d %H:%M:%S": Second is out of range 0..59: '60'
ConvError: Formula (67): DATETIMEPARSE: Cannot convert "2021-05-12 14:07:60" to a date/time with format "%Y-%m-%d %H:%M:%S": Second is out of range 0..59: '60'

 

looks like its working, but then in above scenarios its not working as expected. Instead of giving 14:08:00, it gives as 14:07:60

Amol_Telore
11 - Bolide

@Alteryx_Geek Could you share some sample data where you are getting this error. It will help us to identify the issue. 

Alteryx_Geek
8 - Asteroid

@Amol_Telore  - Sure, below is the sample. Highlight orange cells should not change to 14:07:60, but instead it should be 14:08:00

 

 

Alteryx_Geek_1-1658942137077.png

 

binuacs
20 - Arcturus

@Alteryx_Geek 1900-01-00 is not a valid date. Do you want to keep the same date with the time?

Alteryx_Geek
8 - Asteroid

@binuacs - the date format got messed up while copy pasting, you can take it as 2021-05-12

OllieClarke
15 - Aurora
15 - Aurora

@Alteryx_Geek 

Try this formula

IF tonumber(Substring([Input],19))>=0.5 THEN DATETIMEADD(LEFT([Input],19),1,'second')
ELSE LEFT([Input],19)
ENDIF

 

OllieClarke_0-1658943234064.png

 

Hope that helps,

 

Ollie

 

Labels