Search notes:

VBA: date and time related functions

date
dateAdd adds an time-interval to a date.
dateDiff
datePart
dt = dateSerial(yr, mn, dy)
dt = dateValue("August 28, 1970")
day
minute
fileDateTime
formatDateTime
hour
isDate
month
monthName
now()
second
time
timer
timeSerial(hr, mi, ss)
timeValue
weekday
weekdayName
year

Determine first and last day of a month

option explicit

sub main() ' {
    dim dt as date
    dt = now()

    debug.print "First day of month is: " & first_of_month(dt)
    debug.print "Last day of month is:  " & last_of_month(dt)
end sub ' }

function first_of_month(dt as date) as date ' {
    first_of_month = dateSerial(year(dt), month(dt), 1)
end function ' }

function last_of_month(dt as date) as date ' {
    last_of_month = dateAdd("m", 1, dateAdd("d", -1, first_of_month(dt)))
end function ' }

See also

Date and time related VBA modules/classes
VBA functions

Index