# Compare dates

**URL:** <https://forum.servoy.com/t/compare-dates/16580>\
**Category:** Classic Servoy\
**Created:** [October 1, 2012, 12:57pm UTC](https://forum.servoy.com/t/compare-dates/16580 "2012-10-01T12:57:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mskv1309](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@mskv1309](https://forum.servoy.com/u/mskv1309)\
**Post date:** [October 1, 2012, 12:57pm UTC](https://forum.servoy.com/t/compare-dates/16580/1 "2012-10-01T12:57:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![omar](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@omar](https://forum.servoy.com/u/omar)\
**Post date:** [October 1, 2012, 2:30pm UTC](https://forum.servoy.com/t/compare-dates/16580/2 "2012-10-01T14:30:18Z")

</div>

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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![mskv1309](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@mskv1309](https://forum.servoy.com/u/mskv1309)\
**Post date:** [October 1, 2012, 3:54pm UTC](https://forum.servoy.com/t/compare-dates/16580/3 "2012-10-01T15:54:17Z")

</div>

Awesome, GREAT! Thanks Omar
