Tips on date formats

Provides some tips on using ILOG Script to improve the date format.

Setting the date

The set methods on dates perform safety checks. For example, when you try to set the day, the corresponding month must have the correct number of days. If the date is 2011/ February/15 and you try to change the day to 31, an error will occur. Therefore, to avoid errors when you create a new date, you must respect the order: Year / Month / Day.

Modifying the date format

If your date is not in the format you want, you need to use ILOG Script to modify it. See the following example.

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

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

var d1 = converter("2011-07-06 07:00:00.0");
writeln(d1);
}

This code will return a new date in the format day/month/year. So in the example, the date returned is:

06/07/2011 07:00:00.0