Page 122 - Excel Progamming Weekend Crash Course
P. 122

h540629 ch08.qxd  9/2/03  9:33 AM  Page 97


                                                                          SESSION



                                                                                 8










                                Working with Dates and Times










               Session Checklist

               ✔ How the Date data type stores date and time information
               ✔ Creating date values from literal dates
               ✔ Reading the date and time from the system clock
               ✔ Obtaining details about a date

               ✔ Formatting dates and times for display


                    xcel programs frequently need to work with dates and, less often, times. Excel has
                    excellent tools for working with these data types. These capabilities extend to the VBA
               E language, which provides a special data type designed specifically to store date/time
               information.


               The Date Data Type

               VBA provides a special Date data type to store dates and times. Internally, the Date type
               stores a date and/or a time as a floating-point number, as follows:

                   The integer part of the value specifies the date as the number of days since
                   December 30, 1899.
                   The fractional part of the value specifies the time as a fraction of the 24-hour day
                   (.25 is 6a.m., .5 is noon, and so on).
                   A fractional number with no integer part represents a dateless time.

                  For the user or the programmer, dates and times represented in this way are essentially
               meaningless. Fortunately you’ll never (or at most, rarely) need to work with date and time
               values in this raw format. VBA provides all the tools you need for working with dates and
   117   118   119   120   121   122   123   124   125   126   127