The DatePart function allows you to retrieve a specified time period from a given date. For example, if you want to know what quarter of the year a given date is in, the DatePart function will tell you.
Return value The return value for the DatePart function depends entirely on the specified time period. For example, if you’re looking for the weekday for a given date, the return value will be somewhere between 1 and 7. If you’re looking for the quarter of a given date, however, the return value will be somewhere between 1 and 4. The return value is always a number.
Arguments Visual Basic 4 and 5 have some extra “first day of the week” type arguments that are not relevant to the Y2K topic. The main arguments of the DatePart function are interval, which is the time period in question (that is, day, month, year, and so on), and date, which is the date being sought. So for example, the following code will display the number 4, indicating that Christmas Day is in the fourth quarter:
MsgBox "Xmas in Quarter " & DatePart("q", "12/25/96")
Y2K issues It’s the usual story. In Visual Basic 3 and 4, given a short date, Visual Basic will interpret the date as the 1900s. Check the following code, which reports that the year part of a date is 1900:
MsgBox "The year is " & DatePart("yyyy", "1/1/0")