Search notes:

Access SQL: dateValue

dateValue(…) returns the date without time of a date. Thus, it behaves like Oracle's trunc(dt).
However, it will not work on null values.
option explicit

sub dateValueTest() ' {

   dim db as dao.database
   set db =  application.currentDB

 '
 ' Drop table if it already exists:
 '
   if not isNull(dLookup("Name", "MSysObjects", "Name='dateValueTest'")) then db.execute("drop table dateValueTest")


 '
 ' Create test table …
 '
   db.execute("create table dateValueTest(d date, t varchar(19))")

 '
 ' … and fill some values in it:
 '
   db.execute("insert into dateValueTest values (#2012-12-12 12:12:12#, '2012-12-12 12:12:12')")
   db.execute("insert into dateValueTest values (#2001-01-01 00:00:00#, '2001-01-01 00:00:00')")
   db.execute("insert into dateValueTest values (#2023-12-31 23:59:59#, '2023-12-31 23-59:59')")
 '
 ' Using dateValue will not work on null values:
 '
 ' db.execute("insert into dateValueTest values ( null                , 'null'               )")


 '
 ' Use dateValue(…) to get only the date without time.
 '
   dim rs as dao.recordSet
   set rs = db.openRecordset("select dateValue(d) as dt, t from dateValueTest")
   do while not rs.eof ' {
      debug.print (rs!dt & " | " & rs!t)
      rs.moveNext
   loop

end sub ' }
Github repository about-Access, path: /SQL/dateValue.bas
This example prints:
12.12.2012 | 2012-12-12 12:12:12
01.01.2001 | 2001-01-01 00:00:00
31.12.2023 | 2023-12-31 23-59:59

See also

The truncDate() function in CommonFunctionalityDB.
Compare with fix(…)
Access SQL

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...', 1758199971, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Access/SQL/dateValue(96): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78