Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: using date variable in dateDiff in javascript step

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default using date variable in dateDiff in javascript step

    I set a variable in another is read in as a date. In the transformation with the error I do this:

    var now_time = new Date();
    var sixty_second_count = getVariable("SIXTY_SECOND_COUNT", 0);
    var sixty_second_count_plus_one = sixty_second_count + 1;
    var sixty_second_start = getVariable("SIXTY_SECOND_START", now_time);
    if (sixty_second_count == 19) 
        writeToLog("m", "We hit 19 requests");
        setVariable("SIXTY_SECOND_COUNT", 0, "r");
        java.lang.Thread.sleep(60 - dateDiff(sixty_second_start, now_time, "ss"));
        writeToLog("m", "Done waiting for 60 seconds to end");
        setVariable("SIXTY_SECOND_START", new Date(), "r");
        setVariable("SIXTY_SECOND_COUNT", sixty_second_count + 1 , "r");
        writeToLog("m", "60 second count now at: " + sixty_second_count_plus_one);
        writeToLog("m", "Time into 60 second interval: " + dateDiff(sixty_second_start, now_time, "ss"));
    if (dateDiff(sixty_second_start, now_time, "ss") >= 60)
        setVariable("SIXTY_SECOND_START", new Date(), "r");
        setVariable("SIXTY_SECOND_COUNT", 0, "r");
        writeToLog("m", "We reached 60 seconds and reset start time and 60 second interval count");
    I'm getting this error:

    2019/04/29 16:53:27 - js get req body.0 - org.mozilla.javascript.EvaluatorException: Cannot convert 2019-04-29 16:53:27 to java.util.Date (script#41) (script#41)
    Why does the dateDiff function need to convert the date if it is already a date?

  2. #2
    Join Date
    Apr 2008


    Quote Originally Posted by urbanmojo View Post
    Why does the dateDiff function need to convert the date if it is already a date?
    Because all variables in PDI are strings.

    setVariable does an implicit .toString() on anything that is not a string. Parse it into a date when you are declaring your sixty_second_start (getVariable) and tell it how to parse the date.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.