Naive implementation of the difference in days between two dates
489584
private static long daysBetween(Date date1, Date date2) {
        long diff;
        if (date2.after(date1)) {
            diff = date2.getTime() - date1.getTime();
        } else {
            diff = date1.getTime() - date2.getTime();
        }
        return diff / (24 * 60 * 60 * 1000);
    }
1095897
function (date) {
                if (date instanceof Date === false) {
                    throw new ArgumentError(
                        Logger.logMessage(Logger.LEVEL_SEVERE, "SunPosition", "computeJulianDate", "missingDate"));
                }

                var year = date.getUTCFullYear();
                var month = date.getUTCMonth() + 1;
                var day = date.getUTCDate();
                var hour = date.getUTCHours();
                var minute = date.getUTCMinutes();
                var second = date.getUTCSeconds();

                var dayFraction = (hour + minute / 60 + second / 3600) / 24;

                if (month <= 2) {
                    year -= 1;
                    month += 12;
                }

                var A = Math.floor(year / 100);
                var B = 2 - A + Math.floor(A / 4);
                var JD0h = Math.floor(365.25 * (year + 4716)) + Math.floor(30.6001 * (month + 1)) + day + B - 1524.5;

                return JD0h + dayFraction;
            }
223715
function(v) {
            var days = v.split(',').map(function(day) {
                var m = day.match(/([+-]?\d)?(SU|MO|TU|WE|TH|FR|SA)/);
                return [parseInt(m[1],10)||0, WKDAYS.indexOf(m[2])];
            });

            days.sort(function(d1, d2) {
                // Sort by week, day of week
                if(d1[0] == d2[0])
                    return d1[1] - d2[1];
                else
                    return d1[0] - d2[0];
            });

            return days;
        }
1154390
function diff (from, to, term) {
  term = (term || 'day').toLowerCase();
  var t, f;
  switch(TERM[term]) {
  case 'y':
    return this.getAge(from, to);
  case 'm':
    f = this.toDate(from);
    t = this.toDate(to);
    if (!(f && t)) {
      return null;
    }
    return (t.getFullYear() - f.getFullYear()) * 12 + t.getMonth() - f.getMonth() -
      (t.getDate() < f.getDate() ? 0 : 1);
  case 'w':
    f = this.toDate(from);
    t = this.toDate(to);
    return f && t ? parseInt((t - f) / A_WEEK, 10) : null;
  case 'd':
    f = this.toDate(from);
    t = this.toDate(to);
    return f && t ? (t - f) / A_DAY : null;
  case 'h':
    f = this.toDatetime(from);
    t = this.toDatetime(to);
    return f && t ? parseInt((t - f) / A_HOUR, 10) : null;
  case 'i':
    f = this.toDatetime(from);
    t = this.toDatetime(to);
    return f && t ? parseInt((t - f) / A_MINUTE, 10) : null;
  case 's':
    f = this.toDatetime(from);
    t = this.toDatetime(to);
    return f && t ? parseInt((t - f) / A_SECOND, 10) : null;
  case 'ms':
    f = this.toDatetime(from);
    t = this.toDatetime(to);
    return f && t ? t - f : null;
  default:
    return null;
  }
}
612914
function isDayAfter(d1, d2) {
  var day1 = clone(d1).setHours(0, 0, 0, 0);
  var day2 = clone(d2).setHours(0, 0, 0, 0);
  return day1 > day2;
}
1356205
def inc_date(date_obj, num, date_fmt):
    
    return (date_obj + timedelta(days=num)).strftime(date_fmt)
520770
def previous_weekday(date):
    '''
    
    '''
    weekday = date.weekday()
    if weekday == 0:
        n_days = 3
    elif weekday == 6:
        n_days = 2
    else:
        n_days = 1
    return date - datetime.timedelta(days=n_days)
850550
def _interval(dates):
        """"""
        interval = (dates[1] - dates[0]).days
        last = dates[0]
        for dat in dates[1:]:
            if (dat - last).days != interval:
                return 0
            last = dat
        return interval
14599
def _DateToEpoch(date):
  """"""
  tz_zero = datetime.datetime.utcfromtimestamp(0)
  diff_sec = int((date - tz_zero).total_seconds())
  return diff_sec * 1000000
688837
function leapdays(y1, y2) {
      y1--;
      y2--;
      return (Math.floor(y2/4) - Math.floor(y1/4)) - (Math.floor(y2/100) - Math.floor(y1/100)) + (Math.floor(y2/400) - Math.floor(y1/400));
    }
380135
function dayOfWeek() {
        $num = func_num_args();
        if ($num == 3) {
            $args = func_get_args();
            $y = $args[0];
            $m = $args[1];
            $d = $args[2];
        }
        else {
            $y = $this->year;
            $m = $this->month;
            $d = $this->day;
        }
        $d += $m < 3 ? $y-- : $y - 2;
        return ((int)(23 * $m / 9) + $d + 4 + (int)($y / 4) - (int)($y / 100) + (int)($y / 400)) % 7;
    }
637915
static public function daysBetweenDates(string $date1, string $date2):? int
    {
        // If input dates have datetime 'Y-m-d X' format, take only the date part
        list($d1) = array_pad(explode(' ', $date1), 1, 0);
        list($d2) = array_pad(explode(' ', $date2), 1, 0);

        if (!self::checkDate($d1) || !self::checkDate($d2)) {
            return null;
        }

        if (!($dates = self::splitDates($d1, $d2))) {
            return null;
        }

        return (count($dates) - 1);
    }
851480
def days_in_lunar_date(y)
      sum = 348  
      i = 0x8000  
      while i > 0x8  
        if ((@@lunar_info[y - 1900] & i) != 0)   
          sum += 1  
        end   
        i >>= 1  
      end
    
      sum + leap_days(y)
    end
618428
private int diff360EIsda(final LocalDate start, final LocalDate end) {
        if (start.equals(end)) {
            return 0;
        }
        int dayStart = start.getDayOfMonth();
        int dayEnd = end.getDayOfMonth();
        if (start.getMonth().length(start.isLeapYear()) == dayStart) {
            dayStart = CalculatorConstants.MONTH_30_DAYS;
        }
        if (end.getMonth() != Month.FEBRUARY && end.getMonth().length(end.isLeapYear()) == dayEnd) {
            dayEnd = CalculatorConstants.MONTH_30_DAYS;
        }
        return (end.getYear() - start.getYear()) * CalculatorConstants.YEAR_360 + (end.getMonthValue() - start.getMonthValue()) * CalculatorConstants.MONTH_30_DAYS + dayEnd - dayStart;
    }
979573
function getDateDiff (startDate, endDate, rules) {
  var startTime, endTime, item, diffTime, rule, len, index
  var result = { done: false, time: 0 }
  startDate = toStringDate(startDate)
  endDate = endDate ? toStringDate(endDate) : new Date()
  if (baseExports.isDate(startDate) && baseExports.isDate(endDate)) {
    startTime = getDateTime(startDate)
    endTime = getDateTime(endDate)
    if (startTime < endTime) {
      diffTime = result.time = endTime - startTime
      rule = rules && rules.length > 0 ? rules : setupDefaults.dateDiffRules
      result.done = true
      for (index = 0, len = rule.length; index < len; index++) {
        item = rule[index]
        if (diffTime >= item[1]) {
          if (index === len - 1) {
            result[item[0]] = diffTime || 0
          } else {
            result[item[0]] = Math.floor(diffTime / item[1])
            diffTime -= result[item[0]] * item[1]
          }
        } else {
          result[item[0]] = 0
        }
      }
    }
  }
  return result
}
1154942
private static int dayDiff(final Calendar start, final Calendar end) {
        final long diff = Math.abs(start.getTimeInMillis() - end.getTimeInMillis());
        final double dayDiff = (double) diff / MILLIS_IN_DAY;
        return (int) Math.round(dayDiff);
    }
978720
function DaysToNow(){ // as datetime object returns difference in seconds
		if(empty(self::$dtnow)){
			self::$dtnow=new \DateTime();
			}
		//Get difference
		$diff=$this->diff(self::$dtnow);
		$diff_days =$diff->format('%r').($diff->days);
		return $diff_days;
		}