You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

SPSS Modeler计算跨天日期差出现负值问题求助

Hey there, let's tackle this time difference issue you're facing in SPSS Modeler. I've run into similar quirks with the TIME_HOURS_DIFFERENCE function before, so here are a few targeted checks and fixes to try:

1. Double-check the parameter order of TIME_HOURS_DIFFERENCE

This function follows the syntax TIME_HOURS_DIFFERENCE(time1, time2), which calculates time1 minus time2 in hours. If you want the positive hour difference between arrival and departure (arrive time minus depart time), make sure your function is written as:

TIME_HOURS_DIFFERENCE(arrive_Date, Depart_Date)

If you accidentally reversed the parameters (e.g., TIME_HOURS_DIFFERENCE(Depart_Date, arrive_Date)), cross-day calculations will naturally return negative values since departure time is earlier than arrival time.

2. Ensure your fields are full Date/Time types (not just Time)

If arrive_Date and Depart_Date only store time values (no date component), even with "Rollover days/mins" enabled, Modeler can't recognize cross-day logic. For example, if arrival time is 08:00 (next day) but stored as a standalone time field, the system treats it as the same day's 08:00—subtracting the previous day's 20:00 (also stored as same-day time) will give -12 instead of the correct positive value.

  • Fix: Verify both fields are set to the Date/Time type (with full year-month-day and time components). If you have separate date and time fields, merge them using:
    DATE_AND_TIME(arrive_Date_field, arrive_Time_field)
    

3. Confirm the "Rollover days/mins" setting is properly applied

Even though you mentioned enabling this, it's worth a quick recheck:

  • Go to Edit > Stream Properties > Data tab
  • Ensure the box for "Rollover days/mins for time calculations" is checked
  • After adjusting this setting, re-run your entire stream (not just the calculation node) to make sure the change takes effect.

4. Alternative calculation using DATE_DIFF (if all else fails)

If the function still behaves unexpectedly, you can explicitly combine date and time calculations to bypass rollover ambiguities:

DATE_DIFF(arrive_Date, Depart_Date, "days") * 24 + TIME_HOURS_DIFFERENCE(arrive_Date, Depart_Date)

This formula first calculates the full day difference (converted to hours) and adds the remaining time-hour difference. For example:

  • Arrive: 2024-05-20 08:00, Depart: 2024-05-19 20:00
  • DATE_DIFF returns 1 day → 1*24 = 24 hours
  • TIME_HOURS_DIFFERENCE returns -12 hours (08:00 - 20:00)
  • Total: 24 + (-12) = 12 hours (correct positive value)

内容的提问来源于stack exchange,提问作者Saud

火山引擎 最新活动