pentaho-spoonspool

How to round time to nearest hour in spoon pentaho


I have a datetime field in this format "dd/MM/yyyy, HH:mm:ss".

I nedd to get the nearest up hour using spoon tranformation options.

Any suggestion?

For example: Original date and time object: 10/08/2021, 15:51:25 Date and Time in Integer Format: 10/08/2021, 16:00:00

Thank you in advance.


Solution

  • You can use the Modified JavaScript value step to round time to the nearest hour using JS and then use the Select values step to format the date.

    function roundToHour(date) {
      p = 60 * 60 * 1000; // milliseconds in an hour
      return new Date(Math.round(date.getTime() / p ) * p);
    }
    
    var new_dt = roundToHour(dt);
    
    var new_dt_fmt = roundToHour(dt);
    

    demo