cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
sweetycha
Level III

Extract hours to the nearest hours from duration ( hour:min) format

Hi Guys

how to extract hours from the duration ( hr:min) formant and round the min into the hours

example:

15:26 : 15 hours and 26 min

I want : 15

16:38: 16 hours and 38 mins

I want :17 as 38 min is over 30 mins

 

Appreciate your help

3 ACCEPTED SOLUTIONS

Accepted Solutions
sweetycha
Level III

Re: Extract hours to the nearest hours from duration ( hour:min) format

Thank you.

How to re format the round into  hour only  value i.e for 12 hours  we want 12 not 12:00:00 to make it numeric value

View solution in original post

txnelson
Super User

Re: Extract hours to the nearest hours from duration ( hour:min) format

Go to the Column Info for the formula column and select a Format to use.  Since there is not a direct format that will just display the Hour component of a time based column, you need to select a "Custom" format.  The value you need to specify for the custom format is

Hour( value )
Jim

View solution in original post

Re: Extract hours to the nearest hours from duration ( hour:min) format

I took a different approach. I abandoned time and directly obtained hours. Here is the resulting table:

 

table.JPG

 

Here is the formula that I used.

 

formula.JPG

 

I attached the modified data table for you.

View solution in original post

6 REPLIES 6
txnelson
Super User

Re: Extract hours to the nearest hours from duration ( hour:min) format

Here is how I do it

Names Default To Here( 1 );

time=informat("15:22:00","h:m:s");
show(format(round(time/inhours(1))*3600,"h:m:s"));

time=informat("10:49:00","h:m:s");
show(format(round(time/inhours(1))*3600,"h:m:s"));
Jim
sweetycha
Level III

Re: Extract hours to the nearest hours from duration ( hour:min) format

Thank you

Is there a way to do this without a script? I am not familiar with JMP programming but I run sas programming.

Is not then how to recode this with my actual variable name that is called "hours" and is in duration ( hr:min) formant. I would like to create a col hours1 and extract the hours and do the rounding?

txnelson
Super User

Re: Extract hours to the nearest hours from duration ( hour:min) format

Attached is a data table with a time column and a formula column called Rounded that rounds the hours using the formula

Round( :Time / In Hours( 1 ) ) * 3600

rounded.PNG

 

Jim
sweetycha
Level III

Re: Extract hours to the nearest hours from duration ( hour:min) format

Thank you.

How to re format the round into  hour only  value i.e for 12 hours  we want 12 not 12:00:00 to make it numeric value

txnelson
Super User

Re: Extract hours to the nearest hours from duration ( hour:min) format

Go to the Column Info for the formula column and select a Format to use.  Since there is not a direct format that will just display the Hour component of a time based column, you need to select a "Custom" format.  The value you need to specify for the custom format is

Hour( value )
Jim

Re: Extract hours to the nearest hours from duration ( hour:min) format

I took a different approach. I abandoned time and directly obtained hours. Here is the resulting table:

 

table.JPG

 

Here is the formula that I used.

 

formula.JPG

 

I attached the modified data table for you.