Search code examples
oracle-apex

How to prevent user select start date bigger than end date in date picker calender?


I have 2 date picker calendar start date and end date How can I check and compare when the user select end date must be bigger than start date in oracle apex ?

How to use validation and prevent user select start date bigger than end date like this code example :

if (:P5_START_DATE > :P5_END_DATE) THEN return error "Start date must be less than end date"

enter image description here


Solution

  • Items are treated as strings, so you'll have to convert them to date datatype values, and then do the comparison.

    Create validation that returns error text as e.g.

    if to_date(:P5_START_DATE, 'dd/mm/yyyy') > to_date(:P5_END_DATE, 'dd/mm/yyyy') then
       return 'Start date must be less than end date';
    end if;
    

    Mind the quotes! Your example shows you used double ones; that won't work in Oracle - strings are enclosed into single quotes.