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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758200331, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/VBA/functions/time-date/index(125): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78