Getting Date and Time Information

Sometimes you need to obtain information about a date or a time, such as what day of the week a specified date falls on. VBA has several functions for this purpose. The most flexible of them is DatePart. The syntax is

DatePart(interval, date, firstdayofweek, firstweekofyear)

Interval is a string specifying the interval of interest. The possible values are the same as shown in Table 16.1. Date is the date value you are getting information about. Firstdayofweek is an optional argument indicating which day is to be considered the first day of the week. Settings are shown in Table 16.2. Firstweekofyear is an optional argument indicating which week is to be considered the first week of the year. Settings are shown ...

Get Office® XP Development with VBA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.