cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
New to using JMP? Hit the ground running with the Early User Edition of Discovery Summit. Register now, free of charge.
Register for our Discovery Summit 2024 conference, Oct. 21-24, where you’ll learn, connect, and be inspired.
Choose Language Hide Translation Bar
dn610
Level III

Converting Military Time to h:m:s format

Hi - I am trying to convert a column with military time in character format (e.g. 130749 ) to h:m:s format in jsl. Can someone please help?Thanks.

 

 

5 REPLIES 5
jthi
Super User

Re: Converting Military Time to h:m:s format

Informat + Format pattern is one option

Names Default To Here(1);
Informat("130749", "Format Pattern", "<hh24><mm><ss>");


:0:13:07:49;
:0:13:07:49 + 0; // 47269

// Seconds since JMP's time start (midnight January 1, 1904)
// https://www.jmp.com/support/help/en/18.0/index.shtml#page/jmp/date-and-time-functions.shtml
-Jarmo
dn610
Level III

Re: Converting Military Time to h:m:s format

So I'm actually looking to convert the military time to h:m:s AM/PM format. So for example, 130749 would be 1:07:49 PM. Is this possible?

jthi
Super User

Re: Converting Military Time to h:m:s format

You can convert that datetime to whatever you wish to. I assume you want it back to a string in which case you can for example use Format + Format Pattern

Names Default To Here(1);

Format(Informat("130749", "Format Pattern", "<hh24><mm><ss>"), "Format Pattern", "<hh>:<mm>:<ss> <AMPM>"); // "1:07:49 PM"

 

-Jarmo
dn610
Level III

Re: Converting Military Time to h:m:s format

Is format pattern only available starting with JMP16? I have JMP 15. 

jthi
Super User

Re: Converting Military Time to h:m:s format

I don't remember when it was introduced, either in JMP16 or 17. You can maybe still do it with Informat/Format but I'm not sure how as time handling was clunky in JMP before format pattern (and it still is due to how it handles different time formats on different machines with different settings). So I would build it from parts, this might work

Names Default To Here(1);

template = "^hh12^:^mm^:^ss^ ^ampm^";

str = "130749";

hh24 = Num(Left(str, 2));
mm = Substr(str, 3, 2);
ss = Right(str, 2);

ampm = "";
If(hh24 == 0,
	hh12 = 12;
	ampm = "AM";
, 12 <= hh24 <= 23,
	hh12 = Mod(hh24, 12);
	ampm = "PM"
,
	ampm = "AM";
	hh12 = hh24;
);

timestr = Eval Insert(template);
-Jarmo