Search notes:

VBA: data type date

A date literal allows to «hard code» a specific date/time unambigously, that is independent from the currently used locale.
A (variable) date (without time) can be constructed from three integer-variables with dateSerial(year, month, day).
Similarly, timeSerial(hr, min, sec) constructs a time.
The functions now returns the current date and time, date just returns the current date.
format can be used to convert a date into a string.
Using year(), month(), day(), hour(), minute() and second() to extract the respective parts of a date as integer.
Date arithmetic is possible with dateAdd(…) and dateDiff(…).
These functions add a given number of days to a date or return the number of days between two given days, respectively
Internally, a date is stored as double. the decimal places store the time fraction of a day and the non-decimal places the days since a given date.
The default value for a date is 1899-12-30 00:00:00.
cDate is a conversion function that converts the input parameter to da date.

Internal representation

VBA stores a date as a (8 byte) IEEE-754 floating point value (as is also a double).
The value 0.0 corresponds to midnight (start of) December 30th, 1899:
? format(cDate(0.0), "yyyy-mm-dd hh:nn:ss")
1899-12-30 00:00:00
? format(cDate(0.0 + 1.0/86400), "yyyy-mm-dd hh:nn:ss")
1899-12-30 00:00:01
? format(cDate(1.0), "yyyy-mm-dd hh:nn:ss")
1899-12-31 00:00:00

See also

datatypes

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...', 1758194178, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/VBA/language/datatypes/date/index(80): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78