Free Trial

Alteryx Designer Desktop Discussions

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

Formula for converting 12 hour time to 24 hour time

saltysnax
5 - Atom
TimeAM/PM
3.49PM
10.15AM
10.09PM
12.00PM
12.00AM
9.00AM
5.15PM

 

Hi, I'm trying to work out how to convert 12 hour time to 24 hour time. Apologies if this has been answered before but i couldn't find one in it's basic form like this.

 

I saw someone else came up with this

 

IF [AM/PM] = 'PM' && Left([Time of Usage],2)!='12'

THEN DateTimeAdd('1970-01-01 ' + [Time of Usage], 12, 'hours')
ELSE [Time of Usage]
ENDIF

 

But since the columns here are only Time and AM/PM I changed it to

 

IF [AM/PM] = 'PM' && Left([Time],2)!='12'

THEN [Time], 12, 'hours')
ELSE [Time]
ENDIF

 

Is that at all correct?

 

But then I also thought that because noon is PM and midnight is AM, they would turn out 2400, 1200 respectively. I'm not sure how to account for that.

3 REPLIES 3
AkimasaKajitani
17 - Castor
17 - Castor

Hi @saltysnax 

 

You can use this function.

 

DateTimeParse(Replace(ToString([Time],2),".",":") + " " +[AM/PM],"%I:%M %P")

 

AkimasaKajitani_0-1608251212808.png

 

 

saltysnax
5 - Atom

thank you, apologies but very new to this. is that output for python?

AkimasaKajitani
17 - Castor
17 - Castor

No. This is made by Formula tool.

Please refer the uploaded workflow.

Labels
Top Solution Authors