oracle-apex

How to select today date and time in date picker field by default


How can I select today date and time in oracle apex form field Date picker by defult,

I tried to select default value but its not show when open the form in update mode

I tried first choice static value SYSDATE but not show

also tried from default SQL QUERY :

SELECT SYSDATE FROM DUAL; 

but also not show the date

for time I enabled option to show time in the field and tried to select date and time but also not show the date and time

what is the missing please and thank you in advance


Solution

  • In APEX all page items are strings in the DOM. So, to get a value in a page item, make sure you have a string representation of the date value you want. That implies including the time portion.

    Here is one way. Use a PL/SQL Expression to return a DATE in a format that includes the time portion.

    enter image description here

    Output:

    enter image description here

    So... why did the 2 solutions you mention not work ?

    1. "Static Value". That is just text. If you put static value "SYSDATE" then the value of the page item will be "SYSDATE", not the actual sysdate... I suggest you try this with a page item of type text.

    2. SQL Query SELECT SYSDATE FROM DUAL. As I stated, page items in the DOM are just text. That means that you're relying on the session settings to do an implicit conversion to text. In a database session, the default setting for date format is the parameter NLS_DATE_FORMAT. In Oracle APEX, this can be manipulated in Application > Shared Components > Application Definition > Globalization > "Application Date Format". Change the format mask for this attribute to a date format with a time portion and the SELECT SYSDATE FROM DUAL query will produce a value that includes the time portion and can be used as date picker item source.