Press "Enter" to skip to content

Display Any Country’s Current Date and Time in Oracle Forms

I have created an Oracle Form which shows a country list and a text box to display the current date and time for the selected country. Below is an image.

dynamic time in oracle forms

Objects Created For This in Oracle Form

  1. Data Block
  2. Canvas
  3. List Item
  4. Text Box
  5. Record Group
  6. When-New-Form-Instance Trigger
  7. When-List-Changed Trigger
  8. Database Function

Record Group Query

Record Group created to get the country list from V$TIMEZONE_NAMES view. The query is as follows:

SELECT DISTINCT tzname, tzname tzname1
FROM V$TIMEZONE_NAMES
ORDER BY tzname;

When-New-Form-Instance Trigger Code

Trigger When-New-Form-Instance created to populate the list as shown below:

Declare
n number;
Begin 
clear_list('demo.tzonelist');
n := populate_group('tzone');
populate_list('demo.tzonelist', 'tzone');
End;

When-List-Changed Trigger Code

Trigger When-List-Changed created to display current date and time in the text item. Trigger code is as follows:

Begin
SELECT get_current_local_time (:demo.tzonelist)
into :demo.ctime FROM DUAL;
:tlabel := 'Current Date and Time at: '|| :demo.tzonelist;
End;

Database Function

Created a database function get_current_local_time to get the current time for a country passed as a parameter.

You can download the database function script and the Oracle form from the following link:

Download Source Code

You will find a SQL script in the zip file function_get_time.sql. First, install this script into your database schema to create the function. Then open the form worldclock.fmb in Oracle form builder and run it.

See also: