如何向上或向下舍入日期?你好,
如果我有一堆格式为 MMDDYYYY hh:mm 的开放时间,并且我想修复凌晨 1 点到凌晨 3:59 之间发生的任何日期,以“四舍五入”到凌晨 4 点。
换句话说,如果我的开放时间是 10/09/2020 凌晨 3:12,我需要将其四舍五入到 10/09/2020 凌晨 4:00。
相反,我有相同格式的关闭时间,我想修复凌晨 1 点到凌晨 3:59 之间发生的任何日期,以“向下舍入”到凌晨 1 点。
换句话说,如果我的关闭时间是 10/09/2020 凌晨 3:12,我需要将其向下舍入为 10/09/2020 凌晨 1:00。
我对所有公式都使用 JMP 中的公式编辑器,因此如果我可以将解决方案粘贴到公式编辑器中,那就太棒了!
我附上了一个样本表。
感谢您对此提供的任何帮助。
菲奥娜
大规模定制回复:如何向上或向下舍入日期?太感谢了。
这有效!
回复:如何向上或向下舍入日期?最有可能的是有更清洁/更有效的方法来做到这一点,但这些应该有效:
开放时间四舍五入:
If(In Hours(1) <= Time Of Day(:Opentime) < In Hours(4),
(:Opentime - Time Of Day(:Opentime)) + In Hours(4),
:Opentime
)
圆形关闭时间的想法相同:
If(In Hours(1) <= Time Of Day(:Closetime) < In Hours(4),
(:Closetime - Time Of Day(:Closetime)) + In Hours(1),
:Closetime
)
当您右键单击日期列上的列名称时,基于 JMP“预制”公式构建的解决方案日期和一天中的时间:

回复:如何向上或向下舍入日期?该脚本说明了该方法:
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 );
实际的公式可能会被压缩到此表达式中,假设您需要一个具有所需格式列属性的数值:
:date time - Modulo( :date time, In Hours( 1 ) ) + In Hours( 1 )
请注意,向下舍入到最接近的小时只会删除表达式末尾添加的一小时。