cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
rmthomas
Level III

How to change a column to time if its in a strange format

Hello Everyone, 

 

I have a column that has time in it and its formatted like this 01h17m03s I would like to make this continuous data and everything I try to do doesn't work. Could I use a script to change this?

 

Any ideas would tremendously help out.

 

Thanks,

 

-Ryan

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: How to change a column to time if its in a strange format

You could use a formula where :txt is your column with time:

InHours(Num(Word(1, :Txt, "hms"))) + InMinutes(Num(Word(2, :Txt, "hms"))) + Num(Word(3, :Txt, "hms"))

And then change the column to Numeric continuous and format as Time h:m:s (might differ depending on your time format)

jthi_1-1635255888290.png

 

 

-Jarmo

View solution in original post

Re: How to change a column to time if its in a strange format

Names Default to Here( 1 );

// make data like 01h17m03s
dt = New Table( "Time",
	Add Rows( 10 ),
	New Column( "Original", Character, Ordinal ),
	New Column( "Converted", Numeric, Continuous, Format( "H:M:S" ) )
);

// utility
padded = Function( { l, h }, { v },
	v = Random Integer( l, h );
	v = If( v < 10, "0", "" ) || Char( v );
);

// populate original value
For Each Row(
	h = padded( 0, 24 );
	m = padded( 0, 60 );
	s = padded( 0, 60 );
	:Original = Concat( h, "h", m, "m", s, "s" );
);

// now convert it to JMP time number
For Each Row(
	:Converted = Eval(
		Parse(
			Regex( :Original,
				"(\d\d)h(\d\d)m(\d\d)s",
				"\3 + 60*(\2) + 3600*(\1)"
			)
		)
	)
);

View solution in original post

2 REPLIES 2
jthi
Super User

Re: How to change a column to time if its in a strange format

You could use a formula where :txt is your column with time:

InHours(Num(Word(1, :Txt, "hms"))) + InMinutes(Num(Word(2, :Txt, "hms"))) + Num(Word(3, :Txt, "hms"))

And then change the column to Numeric continuous and format as Time h:m:s (might differ depending on your time format)

jthi_1-1635255888290.png

 

 

-Jarmo

Re: How to change a column to time if its in a strange format

Names Default to Here( 1 );

// make data like 01h17m03s
dt = New Table( "Time",
	Add Rows( 10 ),
	New Column( "Original", Character, Ordinal ),
	New Column( "Converted", Numeric, Continuous, Format( "H:M:S" ) )
);

// utility
padded = Function( { l, h }, { v },
	v = Random Integer( l, h );
	v = If( v < 10, "0", "" ) || Char( v );
);

// populate original value
For Each Row(
	h = padded( 0, 24 );
	m = padded( 0, 60 );
	s = padded( 0, 60 );
	:Original = Concat( h, "h", m, "m", s, "s" );
);

// now convert it to JMP time number
For Each Row(
	:Converted = Eval(
		Parse(
			Regex( :Original,
				"(\d\d)h(\d\d)m(\d\d)s",
				"\3 + 60*(\2) + 3600*(\1)"
			)
		)
	)
);