Page 129 - Excel Progamming Weekend Crash Course
P. 129

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




                104                                                         Saturday Morning

                  Date is the date expression to be formatted. NamedFormat is an optional constant that
               specifies how the date is formatted. See Table 8-5 for possible settings. The function returns
               a string containing the formatted date.


               Table 8-5 Constants for the FormatDateTime Function’s NamedFormat Argument
               Constant (value)        Format
               vbGeneralDate (0)       Displays the date (if present) in short date format, and the time
                                       (if present) in long time format. This is the default setting.
               vbLongDate (1)          Displays the date in long date format
               vbShortDate (2)         Displays the date in short date format

               vbLongTime (3)          Displays the time in long time format
               vbShortTime (4)         Displays the time in short time format


                          If the FormatDateTime function does not provide what you need, you can
                          create your own custom date and time formats using the Format function.
                   Tip    See the VBA documentation for details.



                                                   REVIEW
               VBA makes programming with date and time date relatively easy. The Date data type is spe-
               cialized for holding date and time information, and there are numerous functions at your
               disposal for manipulating and formatting date and time information.
                   The Date data type stores a date/time value as a floating-point number, with the
                   integer part representing the date and the fractional part representing the time.
                   VBA recognizes literal dates in many common formats. Date literals must be
                   enclosed in # characters.
                   DatePart is one of several VBA functions that provide detailed information about a
                   date or time.
                   Details of how dates and times are displayed are controlled to some degree by your
                   system settings.
                   VBA automatically formats date and time values for display, but you can have addi-
                   tional control of the formatting by using the FormatDateTime function.
   124   125   126   127   128   129   130   131   132   133   134