Search code examples
oracle-apex

TIMESTAMP Oracle Apex form


I have a form in apex that I would like to include the localtimestamp not in UTC.

I have a pre-rendering process that looks like this:

:P3_CREATED_DATE_TIME :=  LOCALTIMESTAMP ;

But when the data is displayed on the form it is in UTC.

18-JUN-24 07.29.55.452751000 PM

I was expecting it to be.

18-JUN-24 02.29.55.452751000 PM

Which is what I get when I run this query in the DB.

SELECT localtimestamp FROM dual

Thanks for any help.


Solution

  • Quick test in my "test everything" app:

    select localtimestamp, sessiontimezone from dual;
    

    in the sql workshop AND in my app returned the same value:

    19-JUN-24 05.43.55.020126 AM      +00:00
    

    In shared components > application definition > globalization set "Automatic Time Zone" to On and I got

    19-JUN-24 05.43.55.020126 AM      +02:00
    

    in my app. Check what your settings are. There is a process that sets the time zone for your browser session and that is causing this. If it's not obvious which one it is, run the page in debug - there will be a debug line for this.

    On a side note, for capturing audit values (created_on, updated_on, etc) the best practice is do this in a database trigger instead of in the application. This is because there always is a small latency between when the application item is being set in the application and the transaction is committed to the database - typically your "created on" value in the table should be exactly when the transaction happens and that is when the write operation is done on the server side. The value of the page item will always be off by some franctional seconds and not show the "real" transaction date.