Compare dates

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

Compare dates

Postby mskv1309 » Mon Oct 01, 2012 2:57 pm

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.
mskv1309
 
Posts: 41
Joined: Thu Apr 26, 2012 10:05 pm

Re: Compare dates

Postby omar » Mon Oct 01, 2012 4:30 pm

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.
Intrasoft / JBS Group, Partner
Omar van Galen
Servoy Developer
omar
 
Posts: 315
Joined: Sat Feb 12, 2011 4:51 pm
Location: Intrasoft, The Netherlands

Re: Compare dates

Postby mskv1309 » Mon Oct 01, 2012 5:54 pm

Awesome, GREAT! Thanks Omar
mskv1309
 
Posts: 41
Joined: Thu Apr 26, 2012 10:05 pm


Return to How To

Who is online

Users browsing this forum: No registered users and 1 guest