cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
fionaweston
Level III

How do I round up or round down dates?

Hello,

If I have a bunch of Opentimes in the format MMDDYYYY hh:mm and I would like to fix any of these dates that occur between the hours of 1am and 3:59am to "round up" to 4am.

In other words if my Opentime is 10/09/2020 3:12 AM, I need that to round up to 10/09/2020 4:00 AM.

 

Conversely I have Closetimes in same format and I would like to fix any of these dates that occur between the hours of 1am and 3:59am to "round down" to 1am.

In other words if my Closetimes is 10/09/2020 3:12 AM, I need that to round down to 10/09/2020 1:00 AM.

 

I use the formula editor in JMP for all my formulae so if I can paste the solution into the formula editor that would be great!

I have attached a sample table.

 

Thank you for any help with this.

Fiona

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How do I round up or round down dates?

Most likely there is cleaner/more efficient way to do this but these should work:

 

Rounded opentime:

If(In Hours(1) <= Time Of Day(:Opentime) < In Hours(4),
	(:Opentime - Time Of Day(:Opentime)) + In Hours(4),
	:Opentime
)

Same idea for rounded closetime:

If(In Hours(1) <= Time Of Day(:Closetime) < In Hours(4),
	(:Closetime - Time Of Day(:Closetime)) + In Hours(1),
	:Closetime
)

 

Solution built on the formulas "pre-made" by JMP when you right click on column name on date column for Date and Time Of Day:

jthi_1-1608667237971.png

 

-Jarmo

View solution in original post

3 REPLIES 3

Re: How do I round up or round down dates?

This script illustrates the approach:

 

Names Default to Here( 1 );

date time = 09Oct2020:03:12;

rounded date time = date time - Modulo( date time, In Hours( 1 ) ) + In Hours( 1 );

formatted rounded date time = Format( rounded date time, "m/d/y h:m" );

Show( date time, formatted rounded date time );

The actual formula might be compressed into this expression, assuming that you want a numeric value with the desired Format column attribute:

 

:date time - Modulo( :date time, In Hours( 1 ) ) + In Hours( 1 )

Note that rounding down to the nearest hour would simply remove the addition of one hour at the end of the expression.

jthi
Super User

Re: How do I round up or round down dates?

Most likely there is cleaner/more efficient way to do this but these should work:

 

Rounded opentime:

If(In Hours(1) <= Time Of Day(:Opentime) < In Hours(4),
	(:Opentime - Time Of Day(:Opentime)) + In Hours(4),
	:Opentime
)

Same idea for rounded closetime:

If(In Hours(1) <= Time Of Day(:Closetime) < In Hours(4),
	(:Closetime - Time Of Day(:Closetime)) + In Hours(1),
	:Closetime
)

 

Solution built on the formulas "pre-made" by JMP when you right click on column name on date column for Date and Time Of Day:

jthi_1-1608667237971.png

 

-Jarmo
fionaweston
Level III

Re: How do I round up or round down dates?

Thank you so much.

This works!!