IT Process Automation

  • 1.  Error using getTime()

    Posted Jul 09, 2018 05:28 AM

    Hi all,

     

    I'm trying to convert a date in PAM but the output is always 0. 

    Example:

    var MyDate = new Date("2011-05-03T18:00:00-00:00");
    Process.x = MyDate.getTime();
    //Process.unixTS = MyDate.getTime()/1000;

     

    This piece of code works fine using javascript outside PAM. However Process.x always returns 0 in PAM for this kind of input.

     

    Any idea how to solve this? Thank you in advance.



  • 2.  Re: Error using getTime()

    Posted Jul 10, 2018 11:17 AM

    Hi Pedro,

    You shouldn't use, for now, the javascript date functions, instead use Pams (parseDate Function - CA Process Automation - 4.3 - CA Technologies Documentation)

     

    The result you want can be optain like this:

     

    Process.dtDate = parseDate('12/10/2009','MM/dd/yyyy')
    Process.dt = Process.dtDate.getTime()

    How to parse your dataformat?

    date - Java SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'") gives timezone as IST - Stack Overflow 



  • 3.  Re: Error using getTime()

    Posted Jul 10, 2018 11:26 AM

    Hi deama10,

     

    Thank you for your contribution. 

    I managed to solve it using some transformations:

    • Replace "T" with " "
    • Discard last 5 characters (-00:00)

     

    Date is now with a difference of 3600 seconds caused by Daylight Saving Time. Any idea how to treat this case?



  • 4.  Re: Error using getTime()

    Posted Jul 10, 2018 12:10 PM

    Solved! 

     

    function dateFormat(date){

    var tmpDate = date;
    tmpDate = tmpDate.substring(0, tmpDate.length-6); //remove os últimos 6 carateres
    tmpDate = tmpDate.replace("T", " "); //substitui o "T" por " "
    tmpDate = tmpDate.replace(new RegExp('-', 'g'), '/'); //substitui todas as ocorrências de '-' por '/'
    var formattedDateTime = formatDate(new Date(tmpDate), 'yyyy/MM/dd HH:mm:ss');

    var unixDate = Math.round(new Date(formattedDateTime).getTime()/1000);

    return unixDate;
    }

     

    var myDate = "2018-05-03T18:00:00-00:00";

    Process.dateSDM = dateFormat(myDate);



  • 5.  Re: Error using getTime()
    Best Answer

    Posted Jul 10, 2018 01:37 PM

    As I said, you just need the right format, the date input is valid, so you shouldn't do all this 

     

    Process.dtDate = parseDate("2011-05-03T18:00:00-00:00","yyyy-MM-dd'T'HH:mm:ssX")
    Process.dt = Process.dtDate.getTime();

     

    this will get, in pam

     

    Using javascript console, you will gate the same result



  • 6.  Re: Error using getTime()

    Posted Jul 11, 2018 04:16 AM

    Marcel, the results using your method are slightly different than mine. 

     

    Using the exact two lines of code you provided the result is 1525370400000. Using mine the result is 1304442000 (I divided by 1000).

    There is one hour difference between both methods. Any idea why?