Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Date format, parsing

    Posted 02/07/12 11:40 AM

    Originally posted by: SystemAdmin


    Hi,

    I am trying to use date input in OPL script. The input format I am getting is "2011-07-06 07:00:00.0", which does not work with Date.parse("2011-07-06 07:00:00.0"). It is expecting date to be in the format of "3/12/1997 12:45:00 0". Does anyone know how can I handle this?

    Thanks,
    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: Date format, parsing

    Posted 02/07/12 03:19 PM

    Originally posted by: SystemAdmin


    figured it out, but I should say that, it is very hard to find something in OPL help documentation. Below is how it works:

    execute {

    function DateConverter(dateIn) {
    dateTime = dateIn.split(" ");
    date = dateTime[0];
    time = dateTime[1];

    dateSplit = date.split("-");
    dateReverse = dateSplit.reverse();
    dateNew = dateReverse.join("/") + " " + time;

    // or instead of reverse and join we can do
    // dateSplit[2] + "/" + dateSplit[1] + "/" + dateSplit[0] + " " + time;

    writeln("New Date ", dateNew);

    writeln(Date.parse(dateNew));
    }

    DateConverter("2011-07-06 07:00:00.0");
    }

    which returns:
    New Date 06/07/2011 07:00:00.0
    1307444400000

    }
    #DecisionOptimization
    #MathematicalProgramming-General