Search notes:

Access SQL: fix

The VBA function fix(number) returns the integer portion of a number. If used on a date, it returns the day of the date (that is: it behaves as trunc(date) in Oracle).
option explicit

sub main() ' {

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

    dropTableIfExists db, "tq84_fix_test"

    db.execute "create table tq84_fix_test(num number, dt date)"
    db.execute "insert into tq84_fix_test (num, dt) values (14.05, #2018-10-03 09:55:18#)"
    db.execute "insert into tq84_fix_test (num, dt) values (24.69, #2018-05-18 17:12:33#)"

    dim rs as dao.recordSet
    set rs = db.createQueryDef("", "select num, dt, fix(num) as num_, fix(dt) as dt_ from tq84_fix_test").openRecordSet

    dim sep as string
    sep = chr(9) & "| "

    do while not rs.eof ' {
       debug.print(rs!num & sep & rs!dt & sep & rs!num_ & sep & rs!dt_)
       rs.moveNext
    loop ' }

end sub ' }

sub dropTableIfExists(db as dao.database, tableName as string) ' {
  on error goto err_
    db.execute("drop table " & tableName)
    exit sub
  err_:
    if err.number = 3376 then
     '
     ' Ignore »Table … does not exist«.
     '
       exit sub
    end if

    err.raise err.number, err.source, err.description

end sub ' }
Github repository about-Access, path: /SQL/fix.bas

See also

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