Smart Timeframe & Date Range Handling in Oracle APEX (Day, ISO Week, Month, Quarter, Year)

GitHub: oracle-apex-smart-timeframe
Oracle APEX applications almost always require date-based filtering.
Whether you’re building dashboards, reports, KPIs, invoices, or analytics pages, users expect a seamless and intuitive way to filter data by day, week, month, quarter, or year.

The Challenge

Common issues in APEX apps:
  • Date range logic is duplicated across multiple pages
  • Week handling is not ISO-compliant
  • Navigation (previous/next) is implemented inconsistently
  • Custom date ranges break the UI context
  • JavaScript is used where PL/SQL would be more reliable
  • Timeframe selection and date pickers are not synchronized
Goal:
Provide a single, reusable engine that handles all of this centrally and predictably.

Solution Overview

The Smart Timeframe Engine provides:
  • Day selection (single date)
  • ISO Week selection (Monday to Sunday)
  • Month selection
  • Quarter selection
  • Year selection
  • Previous/next navigation
  • Intelligent auto-detection for custom date ranges
  • A clean server-side architecture without JavaScript
All logic is implemented in PL/SQL, making it easy to reuse across multiple APEX applications and pages.

Core Design Principles

  • The UI only displays options and triggers submits
  • A single submit process delegates all logic
  • One PL/SQL package acts as the single source of truth
  • No date calculations are performed in the page
  • No JavaScript is required
This ensures predictable behavior and long-term maintainability.

Repository Structure

All files are located directly in the root of the GitHub repository for easy access:
  • README.md
    Documentation and setup instructions
  • apex_timeframe_package.sql
    Central PL/SQL package containing all timeframe logic
    [SQL]
  • apex_timeframe_view.sql
    View used as List of Values for timeframe detail navigation
    [SQL]
  • apex_page_rendering_process.sql
    Rendering process used to initialize the default state
    [SQL]
  • apex_page_submit_process.sql
    Submit process that calls the central package
    [SQL]

Required APEX Page Items

To use the engine, the following page items must exist with exactly these names:
  • P1410_START_DATE
    Date Picker (format DD.MM.YYYY)
  • P1410_END_DATE
    Date Picker (format DD.MM.YYYY)
  • P1410_TIMEFRAME
    Radio Group with values: D, W, M, Q, Y
  • P1410_TIMEFRAME_DETAIL
    Radio Group using the timeframe detail view as LOV source
Optional item for predefined start behavior:
  • P1410_FILTER_START_OPTION
    Hidden item or Select List (e.g., START_CURRENT_MONTH)

Rendering Process (Initialization)

On page render, an optional rendering process can initialize the date range based on a predefined start option, such as “start with current month.”
This process runs before the page is displayed and prepares the initial timeframe context.
 
SQL

Submit Process (Central Entry Point)

All user interactions are handled by a single submit process:
  • Clicking Day, Week, Month, Quarter, or Year
  • Clicking a specific timeframe detail
  • Using previous or next navigation
  • Submitting a custom date range
The submit process simply calls the central PL/SQL package and passes the current request and page items.
 
SQL

Central Timeframe Package

All timeframe logic is implemented in a single, reusable PL/SQL package.
 
SQL

Timeframe Detail View

This view is used as the List of Values (LOV) source for timeframe navigation.
 
SQL

Custom Date Range Auto-Detection

When a user manually enters a start date and end date and clicks the search button, the engine automatically determines the most suitable timeframe:
  • A single day is treated as Day
  • A full ISO week as Week
  • A full month as Month
  • A full quarter as Quarter
  • A full year as Year
  • Any other range is mapped to the best matching context
This keeps the UI consistent and avoids confusing states.

Why This Works Well in APEX

  • Relies entirely on server-side PL/SQL
  • Uses standard APEX processes and page items
  • Avoids JavaScript complexity
  • Easy to debug and extend
  • Reusable across multiple pages and applications
Once integrated, the same logic can be used for reports, charts, KPIs, and dashboards without any duplication.

Use Cases

  • Management dashboards
  • Reporting applications
  • Analytics pages
  • Invoice and billing systems
  • Monitoring and operational views
Anywhere a consistent date filter is required, this engine can be applied.

Conclusion

Handling timeframes in Oracle APEX does not need to be complex or fragile.
By centralizing all logic in a reusable PL/SQL package and keeping the page implementation clean, you get a robust, predictable, and maintainable solution that scales with your application.
Explore the full implementation:
GitHub: oracle-apex-smart-timeframe
  • Try the Engine: Download the code from GitHub and integrate it into your APEX app for instant, consistent date filtering.
  • Customize as Needed: Adjust the styles and page item names to fit your application’s theme and requirements.
  • Share Your Experience: Let us know how it works for your use case or if you have improvements!
If you want further customization or more visual elements, just let me know!

 {fullWidth}

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

نموذج الاتصال