Apex: Using a Date Format Mask at Application Level

Every Apex application contains a lot of report pages with date columns and form pages with date fields. For all these items you can specify a date format mask. Never asked yourself if it is possible to define that format mask only once at a central place in your application?

With PICK_DATE_FORMAT_MASK you can. This is a user defined substitution string at application level. It is the best way to keep the dates consistent throughout your application.

  1. How to create the PICK_DATE_FORMAT_MASK substitution string?

    Creating the PICK_DATE_FORMAT_MASK substitution string is done on the edit application attributes page. So, navigate to “Edit Attributes” (application level) à “Definition” and scroll down to the “Substitutions” region. Enter “PICK_DATE_FORMAT_MASK” in the “Substitution String” column and enter your date format mask (here “DD-MM-YYYY”) in the “Substitution Value” column. Press “Apply Changes”.

  2. How to use your application format mask on a report page?

    Suppose we have a report page presenting table “EMP” with column “HIREDATE”. For that “HIREDATE” column we want to use our application level format mask.

    Go to the “Column Attributes” page of the column “HIREDATE” and go the “Column Formatting” region. For “Number/Date Format” enter “&PICK_DATE_FORMAT_MASK.”. Press “Apply Changes”.


  3. How to use your application format mask on a form page?

    Suppose we have a form page to create or edit a row from table “EMP”, with also the “HIREDATE” column. For that “HIREDATE” column we want to use a date picker with our application level format mask.

    Go to the “Edit Page Item” page of the item on “HIREDATE” (here “P2_HIREDATE”) and go the “Name” region. For “Display As” choose “Date Picker (use application format mask)”. Press “Apply Changes”.

    This is the result when we run the form page:


  4. Other uses of the PICK_DATE_FORMAT_MASK substitution string

    Formatting data while selecting it from the database can be performed by including the PICK_DATE_FORMAT_MASK in a TO_CHAR function:

    TO_CHAR ( hiredate, :PICK_DATE_FORMAT_MASK )

    Converting the text presentation of a date item to a date using the correct format mask can also be done by using the PICK_DATE_FORMAT_MASK in the TO_DATE function:

    TO_DATE ( :P2_HIREDATE, :PICK_DATE_FORMAT_MASK )

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s