This page gives a brief description of the most useful date functions in
Access VBA. Access Help gives more details and will describe exactly
how these functions operate in your version of Access.
Note that functions are always followed by a pair of brackets even if -
like Date() - there's nothing in between them. The VBA
editor in Access will sometimes remove these brackets but by entering them you are
telling Access that you are attempting to use a function.
Date() |
Gives today's date. Date$() gives it as a string. There is also a Date
command which sets the system date.
|
Day(<date>) |
Gives the day of the month (1 .. 31) of the <date> specified. |
DateAdd(<interval>,<number>,<date>)
|
Adds an interval to <date>. The intervals can be anything from
seconds to years depending on the value of the <interval>
parameter.
|
DateDiff(<interval>, <date1>, <date2>) |
Subtracts <date2> from <date1> and gives the result in the
unit specified by the <interval> parameter.
|
DatePart(<interval>, <datetime>) |
Extracts part of <datetime>, for example the minute, week or
quarter.
|
Format(<datetime>, <format>) |
Returns <datetime> as a text string in the format specified.
|
Hour(<time>) |
Returns the hour of <time> as a number from 0 to 23. |
Minute(<time>) |
Returns the minute of <time> as a number from 0 to 59. |
Month(<date>) |
Returns the month number of <date>. |
Now() |
Returns the current date and time.
|
Second(<time>) |
Returns the second of <time> as a number from 0 to 59. |
Time() |
Returns the current time. Time$()gives it as a string. There is also a
Time command which sets the system time.
|
TimeSerial(<hour>, <minute>, <second>) |
Creates a time value from the three integers supplied. If the <second>
value is 60 or greater then the excess will be added to the minutes. Similarly
with <minute>. If the <hour> is 24 or greater then days will be added
and the function will return a full datetime value.
|
TimeValue(<string>) |
Creates a time value from the string supplied. The string must be of the form
"hh:mm:ss" although the seconds are optional. Unlike
TimeSerial above, this function will only accept
valid times between "00:00:00" and
"23:59:59".
|
WeekDay(<date>) |
Gives the day of the week as a number from 1 to 7. |
Year(<date>) |
Returns the year number of <date>. |