34,333
edits
Changes
→Adjusting a Date or Time
DateAdd(DateInterval.Week, -1, #8/2/2006#)
</pre>
== Retrieving Parts of a Date or Time ==
The interval types listed in the ''DateAdd()'' section abovbe can be used with the Visual Basic ''DatePart()'' function to extract parts of a date or time. The syntax for the ''DatePart()'' function is as follows:
'''DatePart(''' ''interval'', date) As Integer
For example:
<pre>
DatePart(DateInterval.Month, #8/2/2007#) ' Returns 8
DatePart(DateInterval.Day, #8/2/2007#) ' Returns 2
</pre>
== Finding the Interval Between Two Dates or Times ==
The difference between to dates or times can be determined using the Visual Basic ''DateDiff()'' function, the syntax for which is:
'''DateDiff(''' ''interval'', ''Date1'', ''Date2'')
The ''interval'' parameter specifies the unit of time to use when measuring the difference between two date and using the same values as those outlined for the ''DateAdd()'' function covered previously in this chapter. The two date values the represent the dates to compared. The function returns the difference as the number of specified units. For example, if the interval is defined as ''DateInterval.Day'' and the two dates are a week apart, ''DateDiff()'' will return 7.