Page 1 of 1

Compare dates

PostPosted: Mon Oct 01, 2012 2:57 pm
by mskv1309
How to compare two dates in servoy that is I would like check whether date stored in database is current date(not time).

Do I need to add a new routine to compare date, month and year seperately with current date.

Re: Compare dates

PostPosted: Mon Oct 01, 2012 4:30 pm
by omar
Hi,

You could use the following function. Pass in the dates you want to compare, tell the function to ignore the time and if the result is 0 then the dates are the same.

Code: Select all
function DAYSBETWEEN(dDate1, dDate2, lIncludeTime){
   var nDays=0;
   if(!lIncludeTime){
      dDate1=new Date(dDate1.getFullYear(),dDate1.getMonth(),dDate1.getDate());
      dDate2=new Date(dDate2.getFullYear(),dDate2.getMonth(),dDate2.getDate());
      nDays=Math.round((dDate1.valueOf()-dDate2.valueOf())/(60*60*24*1000));
   }else{
      nDays=(dDate1.valueOf()-dDate2.valueOf())/(60*60*24*1000);
   }
   return nDays;
}


This function was provided by Juan Antonio Santana Medina.

Re: Compare dates

PostPosted: Mon Oct 01, 2012 5:54 pm
by mskv1309
Awesome, GREAT! Thanks Omar