I have this query running from JSLink into list. It get current time from moment.js
and compare date with sharepoint column ctx.CurrentItem.Cumplimiento;
and return result into column sCumplimientoInicial
function overrideCumplimiento(ctx) {
var sIconFileName = "";
var currentServerDateTime = moment().format("DD/MM/YYYY");
var sCumplimiento = ctx.CurrentItem.Cumplimiento;
var sCumplimientoInicial = ctx.CurrentItem.Fecha_x0020_Compromiso_x0020_Ini;
if(currentServerDateTime < sCumplimientoInicial){
sCumplimiento = 'Yes'
}else{
sCumplimiento = 'No'
}
return sCumplimiento;
}
Problem is when currentServerTime
is bigger than sCumplimientoInicial
it return "Yes" instead "No", and it always return Yes. Any idea what is wrong there?
I think it is because sCumplimiento
is an string and no date. Because if I select first, second of any month it return no
so it is not comparing from dates just from string. How can I achieve this comparation of dates correctly?
UPDATE: As comments below I try to do it using
var sCumplimientoInicial = moment("ctx.CurrentItem.Fecha_x0020_Compromiso_x0020_Ini");
But I getting "Invalid Date"