home *** CD-ROM | disk | FTP | other *** search
/ CICA 1992 July / Cica_July92.cdr / win3 / misc / we0127.exe / WE0127.TXT
Text File  |  1992-02-19  |  8KB  |  206 lines

  1. ======================================================================
  2.     Microsoft Product Support Services Application Note (Text File)
  3.                         WE0127: Dates and Times
  4. ======================================================================
  5.                                                     Revision Date: 2/92
  6.                                                        No Disk Included
  7.  
  8. The following information applies to Microsoft Excel for Windows
  9. version 3.0.
  10.  
  11.  --------------------------------------------------------------------
  12. | INFORMATION PROVIDED IN THIS DOCUMENT AND ANY SOFTWARE THAT MAY    |
  13. | ACCOMPANY THIS DOCUMENT (collectively referred to as an            |
  14. | Application Note) IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY      |
  15. | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO    |
  16. | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A     |
  17. | PARTICULAR PURPOSE. The user assumes the entire risk as to the     |
  18. | accuracy and the use of this Application Note. This Application    |
  19. | Note may be copied and distributed subject to the following        |
  20. | conditions: 1) All text must be copied without modification and    |
  21. | all pages must be included; 2) If software is included, all files  |
  22. | on the disk(s) must be copied without modification [the MS-DOS(R)  |
  23. | utility DISKCOPY is appropriate for this purpose]; 3) All          |
  24. | components of this Application Note must be distributed together;  |
  25. | and 4) This Application Note may not be distributed for profit.    |
  26. |                                                                    |
  27. | Copyright 1992 Microsoft Corporation. All Rights Reserved.         |
  28. | Microsoft, MS-DOS, and the Microsoft logo are registered           |
  29. | trademarks and Windows is a trademark of Microsoft Corporation.    |
  30.  --------------------------------------------------------------------
  31.  
  32. General Information
  33. -------------------
  34.  
  35. Microsoft Excel for Windows uses serial numbers to keep track of dates
  36. and times. Using this serial number system, you can add, subtract, and
  37. compare dates and times as you do any other number values. This date
  38. and time system begins with the serial number 1.0, which represents
  39. 1/1/1900 0:00:00 (12:00:00 a.m.), and increases by 1.0 for every 24
  40. elapsed hours, ending with the serial number 65380.99999, which
  41. represents 12/31/2078 23:59:59 (11:59:59 p.m.). The integer portion of
  42. the serial number represents the date, and the decimal portion
  43. represents the time.
  44.  
  45. It is important to note that Microsoft Excel for Windows cannot
  46. manipulate dates that extend beyond the range of 1/1/1900 through
  47. 12/31/2078. Using a date outside of this range will result in an
  48. error.
  49.  
  50. Comparing Dates and Times
  51. -------------------------
  52.  
  53. Because Excel uses serial numbers when calculating functions that
  54. involve dates and times, you may get results that are different from
  55. what you expect. For instance, the following function may return FALSE
  56. even if today's date is 1/31/92:
  57.  
  58.       =IF(NOW()=DATEVALUE("1/31/92"),TRUE,FALSE)
  59.  
  60. This function will return TRUE only when the current date and time are
  61. 1/31/92 and 12:00:00 a.m. This is because the NOW function returns the
  62. serial number of the current date and time, which may not equal the
  63. serial number of only the date, which is returned by the DATEVALUE
  64. function. The correct formula for comparing today's date with another
  65. date is:
  66.  
  67.       =IF(TODAY()=DATEVALUE("1/31/92"),TRUE,FALSE)
  68.  
  69. Another workable formula is:
  70.  
  71.       =IF(INT(NOW())=DATEVALUE("1/31/92"),TRUE,FALSE)
  72.  
  73. In the preceding formula, the INT function strips the decimal portion
  74. of the serial number from the NOW function. Thus, the formula returns
  75. TRUE.
  76.  
  77.  
  78. Date Formulas
  79. -------------
  80.  
  81. The following example shows how the various date functions can be
  82. used:
  83.  
  84.          --------------------------------------------------
  85.         |    | A             | B             | C           |
  86.         |--------------------------------------------------|
  87.         | 1  | DATE1         | DATE2         | DIFFERENCE  |
  88.         |--------------------------------------------------|
  89.         | 2  | 12/20/1970    | 1/20/2000     |             |
  90.          --------------------------------------------------
  91.  
  92. 1. To find the number of days between two dates, subtract the earlier
  93.    date from the later date:
  94.  
  95.       =B2-A1
  96.  
  97. 2. To compute the number of days between the current date and the date
  98.    specified in cell B2, use:
  99.  
  100.       =B2-TODAY()
  101.  
  102. 3. To find the number of years, months, and days between two dates,
  103.    use:
  104.  
  105.       =YEAR(B2)-YEAR(A2)-IF(OR(MONTH(B2)<MONTH(A2),
  106.       AND(MONTH(B2)=MONTH(A2),DAY(B2)<DAY(A2))),1,0)&"y"
  107.       &MOD(MONTH(B2)-MONTH(A2),12)-IF(DAY(B2)<DAY(A2),1,0)&"m"
  108.       &B2-DATE(YEAR(B2),MONTH(B2)-IF(DAY(B2)<DAY(A2),1,0),DAY(A2))&"d"
  109.       
  110.    In the above formulas, lines 1 and 2 calculate the number of years
  111.    between the dates in cells A2 and B2. Line 3 calculates the number
  112.    of months between the dates in cells A2 and B2, ignoring years and
  113.    days. Line 4 calculates the number of days between the dates in
  114.    cells A2 and B2, ignoring years and months. The ampersand symbol
  115.    (&) concatenates the formulas together and labels the result with y, 
  116.    m, and d. If you entered these formulas in cell C2 of our example,
  117.    29y0m21d would be the result.
  118.  
  119. 4. To find the number of weekdays between two dates, use:
  120.  
  121.       =B2-A2-INT((B2-A2)/7)*2-IF(WEEKDAY(B2)<WEEKDAY(A2),2,0)
  122.  
  123.    If you entered this formula in cell C2 of the above example, 7581
  124.    would be the result.
  125.  
  126. 5. To increase a date by a given number of years, months, and days,
  127.    use
  128.  
  129.       =DATE(YEAR(A2)+y,MONTH(A2)+m,DAY(A2)+d)
  130.  
  131.    where y, m, and d are the number of years, months, and days by
  132.    which you want to increase the date in cell A2.
  133.  
  134. 6. To determine the total number of days in the month of a given date,
  135.    use:
  136.  
  137.       =DAY(DATE(YEAR(A2),MONTH(A2)+1,0))
  138.  
  139.    In our example, this formula would return 31.
  140.  
  141. 7. To determine the total number of days in the year of a given date,
  142.    use:
  143.  
  144.       =DATE(YEAR(A2)+1,1,0)-DATE(YEAR(A2),1,0)
  145.  
  146.    In our example, this formula would return 365.
  147.  
  148. Time Formulas
  149. -------------
  150.  
  151. The following example shows how the various time functions can be
  152. used:
  153.  
  154.          ---------------------------------------------
  155.         |    | A           | B          | C           |
  156.         |---------------------------------------------|
  157.         | 1  | START       | END        | DIFFERENCE  |
  158.         |---------------------------------------------|
  159.         | 2  | 6:30 AM     | 7:15 PM    | 12:45       |
  160.         |---------------------------------------------|
  161.         | 3  | 7:45 PM     | 10:30 AM   | 14:45       |
  162.          ---------------------------------------------
  163.  
  164.  
  165.  
  166. 1. To find the amount of elapsed time between two given times, simply
  167.    subtract the earlier time from the later:
  168.  
  169.            =B2-A2
  170.  
  171.    The result of this formula will be the serial number representing
  172.    the elapsed hours, minutes, and seconds. To change the serial
  173.    number to a more conventional format, select the cell, choose
  174.    Number from the Format menu, and then select one of the time
  175.    formats, such as h:mm.
  176.  
  177. 2. If midnight falls between your starting and ending times, as in row
  178.    3 of the example, you must account for the 24-hour time difference
  179.    between the serial numbers, as in the following formula:
  180.  
  181.       =MOD(B3-A3,1)
  182.  
  183. 3. To add a series of hours and minutes where the total exceeds 24
  184.    hours, Excel will begin to count over again at 1. For example, if
  185.    you add cells C2 and C3 using a simple sum formula such as
  186.       
  187.       =C2+C3
  188.  
  189.    the result of this formula will be 3:30 if the cell was formatted
  190.    as h:mm, or 1.145833 if the cell was formatted as General. Neither
  191.    result returns the number of hours elapsed as desired. The
  192.    following formula multiplies the sum by 24, which accounts for this
  193.    "roll over" into a new day:
  194.  
  195.       =24*(C2+C3)
  196.  
  197.    This formula will return the correct answer of 27.5 hours.
  198.                                    
  199. More Information
  200. ----------------
  201.  
  202. For an index of all valid date and time functions, see the "Microsoft Excel
  203. for Windows Function Reference," version 3.0, page xvi.
  204.  
  205.  
  206.