[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

1883.0. "Days between Dates" by SUOSWS::GEISELHART () Mon Jul 25 1994 04:05

Hello, 
I am looking for the formula to reckon out the number of days between to dates. 
Can anyone help me with this?? 

Any help would be great, Bianca.
T.RTitleUserPersonal
Name
DateLines
1883.1Try thisVMSDEV::HALLYBFish have no concept of fireMon Jul 25 1994 09:2461
    Convert the dates to Julian date format and subtract the smaller from
    the larger.
    
    The following routines can be used to convert between Julian and
    standard date format. They assume 32-bit longs and would need to
    be adapted if you are bulding 16-bit PC applications.
    
      John
    
unsigned long tojul(unsigned long x)  /* YYMMDD --> Julian date */
{
  float day, month, year, igreg, julday, ja, jy, jm;
  igreg = (15 + 31 * (10 + 12 * 1582));	/* Date of adoption of Greg. Cal. */
  year  = 1900 + (int)(x / 10000);
  if (year < 0.0) year++;
  month = (x/100) - 100 * (x/10000);
  day   = x % 100;
  if (month > 2.0) {jy = year;     jm = month + 1.0;}
  else             {jy = year - 1; jm = month + 13.;}

  julday  = ((unsigned long)(365.250 * jy));
  julday += ((unsigned long)(30.6001 * jm));
  julday += day + 1720995;

  if ((day + 31 * (month + 12 * year)) >= igreg)
  {
    ja = ((unsigned long)(.01 * jy));
    julday += (2.0 - ja);
    julday += (.25 * ja);
  }
  return ((unsigned long)(julday));
}

unsigned long toyymmdd(unsigned long x)	  /* Julian date --> YYMMDD */
{
  long igreg, jalpha, ja, jb, jc, jd, je, id, mm, yy, q;

  igreg = 2299161;
  if (x >= igreg)
  {
    jalpha = (((x - 1867216) - .25) / 36524.25);
    q = .25 * jalpha;
    ja = x + 1 + jalpha - q;
  }
  else ja = x;

  jb = ja + 1524;
  jc = 6680 + ((jb - 2439870) - 122.1) / 365.25;
  q  = .25 * jc;
  jd = 365 * jc + q;
  je = (jb - jd) / 30.6001;
  q  = 30.6001 * je;
  id = jb - jd - q;
  mm = je - 1;
  if (mm > 12) mm = mm - 12;
  yy = jc -4715;
  if (mm > 2) yy--;
  if (yy <= 0) yy--;
  yy = yy - 1900;
  return ((unsigned long)((yy * 10000) + (mm * 100) + id));
}
1883.2if doing it is more important than the formulaAUSSIE::GARSONachtentachtig kacheltjesMon Jul 25 1994 09:4815
    re .0
    
    If the dates are 17-NOV-1858 or later
    
    Other approaches are:
    
    Convert both dates to a day number using LIB$DAY and then subtract the
    results.
    
    *or*
    
    If the number of days is <= 9999 then convert both dates to VMS
    absolute date/time format with SYS$BINTIM, then subtract with
    LIB$SUB_TIMES, then convert back to human readable format with
    SYS$ASCTIM.
1883.3Thanks for help!SUOSWS::GEISELHARTTue Jul 26 1994 03:153
Thanks for replies, I will try it out this evening.

Bianca.
1883.4DELTA_DAYS.COMULYSSE::FINKATue Jul 26 1994 05:1918
$! DELTA_DAYS.COM 	J. FINKA    Nov 1990
$! assume p1 <= p2 and delta < 9995
$ p1 = f$cvtime(p1,"absolute","date")
$ p2 = f$cvtime(p2,"absolute","date")
$ y1 = f$integer(f$cvtime(p1,,"year"))
$ y2 = f$integer(f$cvtime(p2,,"year"))
$ m1 = f$integer(f$cvtime(p1,,"month"))
$ m2 = f$integer(f$cvtime(p2,,"month"))
$ d1 = f$integer(f$cvtime(p1,,"day"))
$ d2 = f$integer(f$cvtime(p2,,"day"))
$ y = (36525 * (y2 - y1) + 3044 * (m2 - m1)) / 100 + d2 - d1
$ i = 0
$ l: x = y + i
$ i = - i
$ if i .ge. 0 then i = i + 1
$ q = f$cvtime(p1 + "+" + f$string(x) + "-","absolute","date")
$ if q .nes. p2 then goto l
$ write sys$output "Delta days : ", x
1883.5HANNAH::OSMANsee HANNAH::IGLOO$:[OSMAN]ERIC.VT240Tue Jul 26 1994 15:4314

Try this right from character cell notes:

    Notes> spawn @hannah::igloo$:[osman.comfiles]subdat 1-jul-1994 1-apr-1993

And of course this one(!):

    Notes> spawn @hannah::igloo$:[osman.comfiles]subdat 11-jul-1994 1-jan-2000




/Eric
1883.6re. .-1OINOH::KOSTASHe is great who confers the most benefits.Wed Jul 27 1994 11:3515
    re. .-1
    
    Hi Eric,
    
      why do I get the same answer for two different dates?
    
    i.e., 
    
    spawn @hannah::igloo$:[osman.comfiles]subdat 20-Nov-1957 27-jul-1994
    spawn @hannah::igloo$:[osman.comfiles]subdat 20-Nov-1963 27-jul-1994
    
    both give: 
    9999 days, 23:59:59.99
    
    /k
1883.7CSC32::D_DERAMODan D&#039;Eramo, Customer Support CenterWed Jul 27 1994 11:487
        The VMS delta time format does not go to 10,000 days or
        beyond.  It is limited to nnnn hh:mm:ss.cc, the maximum
        being 9999 days 23 hours 59 minutes 59.99 seconds.
        
        Reply .2 mentions the restriction.
        
        Dan