Date comparision

confirmit

#1

Can we directly compare two dates in confirmit? I have a requirement to punch a single select question on the basis of a specific date.


#2

I made some similar requirement some time back. plz see the code below, and try if that can help.

if(Request.QueryString("period") == "" || Request.QueryString("period") == undefined || Request.QueryString("period") == null )
  {
	/*
	var dm = new Date(2016, 11,16)

below 16 nov 2016 - 1
above 16 nov 2016 - 15 may 2017 - 2
below 16 may 2017 - 15 nov 2017 - 3
above 16 nov 2017 - 4
	*/
	var dm = new Date();
	var dt = dm.getDate();
	var mn = dm.getMonth() + 1;
	var yr = dm.getYear();

	var newdt1 = new Date(2016, 11,16);
	var newdt2 = new Date(2017, 5,16);
	var newdt3 = new Date(2017, 11,16); 

	if(Math.round((newdt1 - dm)/86400000) > 0 )
	{
	      f('qperiod').set("1");
	}
	else if(Math.round((newdt2 - dm)/86400000) > 0 )
	{
	      f('qperiod').set("2");
	}
	else if(Math.round((newdt3 - dm)/86400000) > 0 )
	{
	      f('qperiod').set("3");
	}
	else
	{
	      f('qperiod').set("4");
	} 
}
else
{
	var period = parseInt(Request.QueryString("period"));
	f('qperiod').set(period);	
}

#3

Thanks @Leader, but why we are dividing dates with 86400000 after subtracting? Is there any particular logic behind it?


#4

86400000 this number is basically the total number of milli seconds in a day. so by dividing the subtraction a two dates with this number gives the value number of days as a time stamp.


#5

Thanks @Leader, now it is clear to me. Now, I can make my logic further. Really appreciate !!!:grinning: