USING DATES AND TIMES

======================================================================
  Microsoft(R) Product Support Services Application Note (Text File)
                     XE0127: USING DATES AND TIMES
======================================================================
                                                   Revision Date: 2/93
                                                      No Disk Included

The information in this Application Note applies to:

 - Microsoft Excel for the Macintosh(R), versions 1.0, 1.03, 1.04,
   1.06, 1.5, 2.2, 3.0, and 4.0
 - Microsoft Excel for Windows(TM), versions 2.0, 2.1, 2.1c, 2.1d,
   3.0, and 4.0

 --------------------------------------------------------------------
| INFORMATION PROVIDED IN THIS DOCUMENT AND ANY SOFTWARE THAT MAY    |
| ACCOMPANY THIS DOCUMENT (collectively referred to as an            |
| Application Note) IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY      |
| KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO    |
| THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A     |
| PARTICULAR PURPOSE. The user assumes the entire risk as to the     |
| accuracy and the use of this Application Note. This Application    |
| Note may be copied and distributed subject to the following        |
| conditions: 1) All text must be copied without modification and    |
| all pages must be included; 2) If software is included, all files  |
| on the disk(s) must be copied without modification [the MS-DOS(R)  |
| utility DISKCOPY is appropriate for this purpose]; 3) All          |
| components of this Application Note must be distributed together;  |
| and 4) This Application Note may not be distributed for profit.    |
|                                                                    |
| Copyright 1990-1993 Microsoft Corporation. All Rights Reserved.    |
| Microsoft and MS-DOS are registered trademarks and Windows         |
| is a trademark of Microsoft Corporation.                           |
| Macintosh is a registered trademark of Apple Computer, Inc.        |
 --------------------------------------------------------------------

                          GENERAL INFORMATION
                          ===================

Microsoft Excel stores all dates as integers and all times as decimal
fractions. With this system, dates and times can be added, subtracted,
or compared like any other numbers. In this date system, the serial
number 1 represents 1/2/1904 12:00 A.M. (midnight) if you are using a
Macintosh computer, or 1/1/1900 12:00:00 A.M. if you are using the
Microsoft Windows operating system. In Microsoft Excel, all dates are
manipulated using this system. Times are stored as decimal numbers
between .0 and .99999, where .0 is 00:00:00 and .99999 is 23:59:59.

The date integers and time decimal fractions can be combined to create
numbers that have a decimal and an integer portion. For example, the
number 32331.06 represents the date and time 7/8/1992 1:26:24 A.M. if
you are using the 1904 (Macintosh) date system, or 7/7/1988 1:26:24
A.M. if you are using the 1900 (Windows) date system. To perform
complex date and time calculations, use the built-in date and time
functions in Microsoft Excel.

           NEW DATE FUNCTIONS IN MICROSOFT EXCEL VERSION 4.0
           =================================================

Microsoft Excel version 4.0 introduces five new date functions: EDATE,
EOMONTH, NETWORKDAYS, WORKDAY, and YEARFRAC. These functions are
included in the Analysis ToolPak add-in macro. For more information
about how to use this macro, see Chapter 4 of the "Microsoft Excel
User's Guide 2".

   Function Name  Purpose
   -------------  -------
                 
   EDATE          This function returns the serial number date that is
                  a given number of months before or after a stated
                  date. Use EDATE to calculate maturity or due dates
                  that fall on the same day of the month as the date
                  of issue.
   EOMONTH        This function returns the serial number date for the
                  last day of the month that is the indicated number
                  of months before or after a stated date. EOMONTH can
                  be used to calculate maturity or due dates that fall
                  on the last day of the month.
   NETWORKDAYS    This function returns the total number of working
                  days, excluding weekends and with an option to
                  exclude holidays. NETWORKDAYS can be used to
                  calculate accrued employee benefits based on the
                  number of days between two dates.
   WORKDAY        This function returns a serial number date that is a
                  given number of working days from a stated date,
                  excluding weekends and with an option to exclude
                  holidays. WORKDAY can be used for calculations in
                  which weekends, holidays, or both are to be
                  excluded, such as the number of days worked or
                  invoice due dates.
   YEARFRAC       This function is used to calculate the fraction of a
                  partial year to a whole year. This fraction can be
                  calculated based on one of the following options:
                  30/360, actual/actual, actual/360, or actual/365.

                             SORTING DATES
                             =============

In Microsoft Excel, dates are sorted based on the serial number of the
date rather than the displayed number. Therefore, when you sort dates
in Microsoft Excel, you may not receive the results you expect. For
example, if you sort a series of dates that are displayed in the mmmm
date format (so that only the month is displayed), the months will not
be sorted alphabetically.

                            COMPARING DATES
                            ===============

Serial numbers also influence date and time comparisons. For example,
when you use the NOW function to compare a date with the current date,
as in the formula

   =IF(NOW()=DATEVALUE("10/1/92"),TRUE,FALSE)

this formula will return FALSE even if the current date is 10/1/92; it
will return TRUE only when the date is 10/1/92 12:00:00 A.M.  If you
are comparing two dates in a formula and you do not need to have the
time included in the result, you can work around this problem by using
the appropriate formula below.

   For Microsoft     
   Excel version(s)   Use the formula
   ----------------   ---------------
                     
   4.0                =IF(TODAY()=DATEVALUE("10/1/92"),TRUE,FALSE)
   3.0 and earlier    =IF(INT(NOW())=DATEVALUE("10/1/92"),TRUE,FALSE)

                         WORKING WITH FORMULAS
                         =====================

DATE FORMULAS
=============

Finding the Number of Days, Months,
and Years Between Now and a Future Date
---------------------------------------

To find the number of days between now and a date sometime in the
future, use the following formula

   ="mm/dd/yy"-NOW()

where "mm/dd/yy" is the future date. Use the General format to format
the cell that contains the formula.

Finding the Number of Days, Months, and Years Between Any Two Dates
-------------------------------------------------------------------

To calculate the number of days, months, and years between two dates
(with the start and end dates entered in cells A1 and A2
respectively), use the DAY, MONTH, and YEAR functions as shown in the
following formula:

   =YEAR(A2)-YEAR(A1)-IF((MONTH(A2)<MONTH(A1))+
    (MONTH(A2)=MONTH(A1))*(DAY(A2)<DAY(A1)),1)&"y"&MONTH(A2)-
    MONTH(A1)+(MONTH(A2)<MONTH(A1))*12-(DAY(A2)<DAY(A1))&"m"&INT(A2)-
    DATE(YEAR(A2),MONTH(A2)-(DAY(A2)<DAY(A1)),DAY(A1))&"d"

This formula can also be broken down into individual segments of days,
months, and years as follows:

   To find this time segment  Use this formula
   -------------------------  ----------------
                             
   The number of days         =INT(A2)-DATE(YEAR(A2),MONTH(A2)-
   between two dates,          (DAY(A2)<DAY(A1)),DAY(A1))&"d"
   ignoring years and months

   The number of months       =MONTH(A2)-MONTH(A1)+
   between two dates,         (MONTH(A2)<MONTH(A1))*
   ignoring years and days    12-(DAY(A2)<DAY(A1))&"m"

   The number of years        =YEAR(A2)-YEAR(A1)-
   between two dates,         IF((MONTH(A2)<MONTH(A1))+(MONTH(A2)=
   ignoring months and days   MONTH(A1))*(DAY(A2)<DAY(A1)),1)&"y"
                             
    NOTE: In the above formulas,  &"d", &"m", and &"y" are optional.
    These characters allow you to distinguish the results as days,
    months, and years, respectively.

To find the number of weekdays between two dates, where the start and
end dates are entered in cells A1 and A2 respectively, use the
appropriate formula below:

   For Microsoft   
   Excel version(s)   Use the formula
   ----------------   ---------------
                   
   4.0                =NETWORKDAYS(A1,A2)

   3.0 and earlier    =A2-A1+1-INT((A2-A1+1)/7)*2-IF(INT((A2-
                      A1+1)/7)=(A2-A1+1)/7,0,
                      IF(WEEKDAY(A2)<WEEKDAY(A1),2,0))-
                      IF(OR(WEEKDAY(A1)=1,WEEKDAY(A2)=7),1,0)

Increasing Dates Incrementally
------------------------------

To increase a date by a number of years, months, or days, use the
formula

   =DATE(YEAR(<reference>)+<value1>,MONTH(<reference>)+<value2>,
   DAY(<reference>)+<value3>)

where <reference> is the cell that contains the date, and <value1>,
<value2>, and <value3> are the increments by which you want to
increase the year, month, and day, respectively.

Calculating the Difference
Between Two Dates in Microsoft Excel Versions 3.0 and 4.0
---------------------------------------------------------

In Microsoft Excel versions 3.0 and 4.0, the function
DAYS360("start_date","end_date") allows you to calculate the
difference between two dates based on a 360-day calendar year. Because
this function is based on 360 days per year, your calculations may
return unexpected values. For example, DAYS360("2/1/91", "3/1/91")
returns 30 days rather than 28 days. To obtain  the number of days
based on a 365-day calendar, subtract one date from the other or use a
combination of the DAY, MONTH, and YEAR functions as they are used in
the above examples.

TIME FORMULAS
=============

Calculating Elapsed Time
------------------------

When you subtract the contents of one cell from another to find the
amount of time elapsed between them, the result will be a serial
number representing the elapsed hours, minutes, and seconds. To make
this number easier to read, use the h:mm time format to format the
cell containing the result. For example, if cells C2 and D2 contain
the formula =B2-A2 and cell C2 is formatted as General (see the table
below), the cell will display a decimal number--in this case, 0.53125
(the serial number representation of 12 hours and 45 minutes). To
display the difference as it is shown in cell D2 below, select cell
D2, choose Number from the Format menu, and select the h:mm time
format.

           A           B                C                      D
   1  Start Time    End Time  Difference (General)   Difference (h:mm)
   2  6:30 AM       7:15 PM   0.53125                12:45

If midnight falls between your start time and end time, you must use a
special formula to account for the 24-hour time difference. For
instance, you could set up the following table, which allows for time
spans beyond midnight:

           A           B               C                    D
   1  Start Time   End Time  Difference (General)   Difference (h:mm)
   2    7:45 PM    10:30 AM       0.61458333              14:45

To set up this table, type the following formula in cells C2 and D2:

   =B2-A2+IF(A2>B2,1)

Accumulating Hours and Minutes Greater Than 24 Hours
----------------------------------------------------

Since Microsoft Excel uses fractions of a day to keep track of times,
you must indicate when a total will be accumulating amounts of time
greater than 24 hours. To instruct Microsoft Excel to keep
accumulating the number of hours after the total exceeds 24, use the
following formula

   =INT(SUM(HOUR(<range>))+SUM(MINUTE(<range>))/60)+
   MOD(SUM(MINUTE(<range>))/60,1)*0.6

where <range> is the range of cells that contain the accumulated time.
Since this is an array formula, you must enter it by pressing
COMMAND+ENTER (on the Macintosh) or SHIFT+CTRL+ENTER (in Windows). The
cell in which you enter this formula should be formatted using the
General format.

USING THE TODAY AND NOW FUNCTIONS IN
MICROSOFT EXCEL VERSIONS 3.0 AND 4.0
====================================

The TODAY function returns the serial number of today’s date based on
your system clock and does not include the time. The NOW function
returns the serial number of today's date and includes the time.

            TRANSFERRING FILES BETWEEN MICROSOFT EXCEL FOR
             THE MACINTOSH AND MICROSOFT EXCEL FOR WINDOWS
             =============================================

By default, Microsoft Excel for the Macintosh uses the 1904 date
system and Microsoft Excel for Windows uses the 1900 date system. This
means that when you enter the serial number 1 in Microsoft Excel for
the Macintosh and format it as a date, it is displayed as 1/2/1904
12:00 A.M. In Microsoft Excel for Windows, the serial number 1 is
displayed as 1/1/1900 12:00 A.M.

If you transfer files from one version of Microsoft Excel to another,
this difference in the date systems can cause dates to be displayed
four years and one day away from their correct date. In Microsoft
Excel for Windows, you can change to the 1904 date system by choosing
Calculation from the Options menu and selecting 1904 Date System under
Sheet Options. In Microsoft Excel for the Macintosh, you can switch to
the 1900 date system by choosing Calculation from the Options menu and
clearing the 1904 Date System check box under Sheet Options.

       MORE INFORMATION ABOUT MICROSOFT EXCEL FOR THE MACINTOSH
       ========================================================

For more information about manipulating dates and times, see the
appropriate manual below.

   Version of                                         
   Microsoft Excel   Manual title                      Page numbers
   ---------------   ------------                      ------------
                                                     
   1.5 and earlier   "Microsoft Excel User’s Guide"    72-74
   2.2               "Microsoft Excel Reference "      179-185, 591-596
   3.0               "Microsoft Excel User's Guide"    86-94, 178-183
   4.0               "Microsoft Excel User's Guide 1"  108-110, 114

For more information about a specific function, see the appropriate
manual below.

   Version of       
   Microsoft Excel   Manual Title
   ---------------   ------------
                   
   1.5 and earlier   "Microsoft Excel Arrays, Functions, and Macros"
   2.2               "Microsoft Excel Functions and Macros"
   3.0               "Microsoft Excel Function Reference"
   4.0               "Microsoft Excel Function Reference"

          MORE INFORMATION ABOUT MICROSOFT EXCEL FOR WINDOWS
          ==================================================

For more information about manipulating dates and times see the
appropriate manual below.

   Version of                                         
   Microsoft Excel           Manual Title               Page numbers
   ---------------           ------------               ------------
                                                     
   2.0, 2.1, 2.1c, and 2.1d  "Microsoft Excel         
                             Reference Guide"           187-193

   3.0                       "Microsoft Excel User's    93-101, 186-191
                             Guide"

   4.0                       "Microsoft Excel User's    108-110, 114
                             Guide 1"

For more information about a specific function, see the appropriate
manual below.

   Version of               
   Microsoft Excel           Manual Title
   ---------------           ------------
                           
   2.0, 2.1, 2.1c, and 2.1d  "Microsoft Excel Functions and Macros"
   3.0                       "Microsoft Excel Function Reference"
   4.0                       "Microsoft Excel Function Reference"

Comments

Popular posts from this blog

BOTTOM LIVE script

Fawlty Towers script for "A Touch of Class"