Hi all,
Is there any way to get a date variable into a standardized format in Design Studio scripting?
I have a BW User Exit Variable for 0CALDAY that is filled with a default key date. It is possible to change this variable during application runtime via scripting. This works fine.
I'd like to link the date variable to a DATEFIELD-object and I am struggling, because I cannot retrieve the variable in a standardized format.
Look:
// Preferred viewing locale: German (Germany) t = DS_1.getVariableValueExt("USO_CD_GSA"); // Returns date in external format - German: dd.mm.yyyy - 21.03.2016 t = DS_1.getVariableValueText("USO_CD_GSA"); // Returns date 21.03.2016 // Preferred viewing locale: English (United States) t = DS_1.getVariableValueExt("USO_CD_GSA"); // Returns date 3/21/2016 t = DS_1.getVariableValueText("USO_CD_GSA"); // Returns date 3/21/2016 // Date field: t = DATEFIELD_1.getDate(); // Returns string yyyymmdd
I could substring the date and build a yyyymmdd-version of it, but this solution is very error-prone as it is not really possible to determine the user's locale.
var d = "3/21/2016"; var sep = d.substring(d.length-5,d.length-4); var yyyymmdd = ""; if(sep == "/") { // m/dd/yyyy var split = d.split("/"); var day_int = Convert.stringToInt(split[1]); var month_int = Convert.stringToInt(split[0]); var month_string = "" + month_int; var day_string = "" + day_int; if(month_int < 10) { month_string = "0" + month_int; } if(day_int < 10) { day_string = "0" + day_int; } yyyymmdd = split[2] + month_string + day_string; // Finally yyyymmdd :-) // What if the date format is 21/03/2016 like in Brazil?
DS 1.6 SP0 and BI 4.1 SP7
Appreciate any help,
Moritz