home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / bbs / waffle / 4305 < prev    next >
Encoding:
Text File  |  1992-11-18  |  2.9 KB  |  70 lines

  1. Path: sparky!uunet!pipex!ibmpcug!exnet2!flatlin!wolferts.ka.sub.org!dkw
  2. From: dkw@wolferts.ka.sub.org (Dr. Klaus Wolferts)
  3. Newsgroups: comp.bbs.waffle
  4. Subject: Re: STATUS File
  5. Message-ID: <XaceuB1w164w@wolferts.ka.sub.org>
  6. Date: Tue, 17 Nov 92 19:38:32 MEZ
  7. References: <gTXcuB7w165w@proteus.qc.ca>
  8. Distribution: world
  9. Organization: Ing'Buro f. EDV + Elektronik, D-7500 Karlsruhe 31
  10. Lines: 58
  11.  
  12. randall@proteus.qc.ca (Randall Reid) writes:
  13.   
  14. > ... I need to write a 4DOS batch file that will calculate the number
  15. > of seconds since Jan 1st 1970 
  16. > So far I figured out (by trial and error):
  17. > seconds =  %@eval[%@DATE[%_date]*24*60*60  (seconds between 1980 and today)
  18. >            + %@time[%_time]                (seconds since midnight)
  19. >            + 315576000                     (seconds between 1970-1980)
  20.  
  21. There were     315532800 seconds from 1/1/70 to 1/1/80 (see below)
  22.  
  23. >            - 25200]                        (seconds in 7 hours)
  24. > I used 365.25 * 10 * 24 * 60 *60  to compute the seconds from 1970-1980.
  25. > I'm not sure if this is entirely accurate considering leap years.
  26.  
  27. More accurate (for your calculation) is (365 * 10 + 2) * 24 * 60 * 60 
  28. for the 10 years, where the + 2 result from the two leap years '72 +'76. 
  29. Your calculation would result in 3652.5 (!) days from 1/1/70 to 1/1/80! 
  30. (Take the half day remaining for a super long sylvester party ;-)
  31.  
  32. > The subtraction of 7 hours from the formula seems to yield the correct result
  33. > although I don't understand the significance of this number.  I arrived at
  34. > it purely by emperical means.
  35. >
  36. > So, can someone tell me if and where I'm going wrong in this formula.  I
  37. > can't help but think that the calculations for leap years must be more
  38. > complex.. perhaps requiring some modulo arithmetic.  And I don't understand
  39. > why subtracting 7 hours seems to work.
  40.  
  41. I don't know how exact the built in date and time calculations are, 
  42. but taking the year with 365.25 days for day or date calculations will  
  43. result in such errors you experienced.
  44.  
  45. Thus the 7 hour subtraction yields the expected result for the months 
  46. 3 to 12/92 only. You will get that correction values changing by 
  47. +/- 6 hours = 0.25 days for every year, because calendar years last 
  48. 365 or 366 days on leap years. 
  49.  
  50. You are quite right using modulo arithmetic for that purpose. 
  51.  
  52. For a little similiar problem (find the day of week (sun..sat = 0..6) 
  53. out of day (1..31), month (1..12) and year (1..1999)), try do use 
  54. the following (TPascal) formula: 
  55.  
  56.    WeekDay:= (Year + Year Div 4 - Ord ((Month<=2) And (Year Mod 4 = 0))
  57.                + Ord (Copy ('033614625035',Month,1)) + Day + 6) Mod 7;
  58. Klaus
  59.  
  60.  
  61.  ____    __  __  __    __   __
  62. |    \  |  |/ / |  | /|  | / / Dr.-Ing. Klaus Wolferts: dkw@wolferts.ka.sub.org
  63.  
  64. |  |  | |  | /  |  |/ |  |/ / Ing'Buro f. EDV + Elektronik  
  65. | d|  | | k| \  | w| /|  | / Mitteltorstr. 45,            Phone: +49 721 706016
  66. |____/  |__|\_\ |__|/ |__|/ D-7500 Karlsruhe 31, Germany,  49°03'02"N 8°22'58"E
  67.