JavaScript Datum in Qlik Format umrechnen

Mit der folgen Funktion kann man ein JavaScript Date() in das Qlik Sense / View Format konvertieren:


function Date2QlikDate(aDate){
var nDate = new Date(aDate); 
var nMonth = nDate.getUTCMonth() +1; 
var nDay = nDate.getUTCDate() +1;
var nYear = nDate.getUTCFullYear();
// DMY to Modified Julian calculated with an extra subtraction of 2415019 - 153 for Q.
var nSerialDate =
parseInt(( 1461 * ( nYear + 4800 + parseInt(( nMonth - 14 ) / 12) ) ) / 4) +
parseInt(( 367 * ( nMonth - 2 - 12 * ( ( nMonth - 14 ) / 12 ) ) ) / 12) -
parseInt(( 3 * ( parseInt(( nYear + 4900 + parseInt(( nMonth - 14 ) / 12) ) / 100) ) ) / 4) +
nDay - 2415019 - 32075 - 153;

if (nSerialDate < 60) {
// Because of the 29-02-1900 bug, any serial date
nSerialDate--;
}
return nSerialDate;
}
Share