Page 126 - Excel Progamming Weekend Crash Course
P. 126

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




                  Session 8 — Working with Dates and Times                               101

                  DatePart offers a great deal of flexibility. The syntax is:

                  DatePart(interval, date, firstdayofweek, firstweekofyear)

                   Interval: The date interval of interest. Possible values for this argument were shown
                   earlier in this session, in Table 8-1, with these exceptions: “y” means day of the year
                   (1–365 or 366), “d” means the day of the month (1–31 for August, for example), and
                   “w” means weekday (1–7).
                   Date: A type Date specifying the date of interest.
                   Firstdayofweek: A constant specifying which day is considered to be the first day
                   of the week. See Table 8-2 for permitted values. This argument is optional; the
                   default is Sunday.
                   Firstweekofyear: A constant specifying which week is considered the first week
                   of the year. See Table 8-3 for possible values for this argument. The argument is
                   optional; the default is the week in which January 1 occurs.


               Table 8-2 Constants for the DatePart Function’s Firstdayofweek Argument

               Constant (value)                    Meaning
               vbUseSystem (0)                     Use the system setting
               vbSunday (1)                        Sunday (the default)
               vbMonday (2)                        Monday

               vbTuesday (3)                       Tuesday
               vbWednesday (4)                     Wednesday
               vbThursday (5)                      Thursday

               vbFriday (6)                        Friday
               vbSaturday (7)                      Saturday



               Table 8-3 Constants for the DatePart Function’s Firstweekofyear Argument

               Constant (value)                    Meaning
               vbUseSystem (0)                     Use the system setting
               vbFirstJan1 (1)                     The week in which January 1 falls (the default)
               vbFirstFourDays (2)                 The first week containing at least four days of
                                                   the new year
               vbFirstFullWeek (3)                 The first seven-day week of the year
   121   122   123   124   125   126   127   128   129   130   131