This discussion is archived
8 Replies Latest reply: Apr 29, 2013 8:38 AM by CraigB RSS

Date Validation Issue

amit srivastava Newbie
Currently Being Moderated
Hello All,

I have two field in form as Start Date and End Date. I need to put a validation such that End date should not be before start data. but I am getting some error. Please suggest how can we acheive this ?

Both the fields are DATE type.

Thanks.
  • 1. Re: Date Validation Issue
    tony.g Journeyer
    Currently Being Moderated
    Hi

    You'll need to show us you code, so we can correct what you have and where it is placed in the form. Also give us the error message you are seeing.

    The version of forms is also very important.

    Tony
  • 2. Re: Date Validation Issue
    CraigB Guru
    Currently Being Moderated
    Please show us what you have tried! Typically, you should be able to check if :END_DATE > :START_DATE but we need to see your code and what trigger executes the code.

    Craig...
  • 3. Re: Date Validation Issue
    amit srivastava Newbie
    Currently Being Moderated
    Hello Tony,

    We are using :

    Forms [32 Bit] Version 10.1.2.0.2 (Production)

    And the code that I write in Validate trigger is :

    declare
              ALERT_BUTTON1 number;
    Begin

    --     set_item_property(:XXONT_CREDITP_HEADERS.END_DATE,format_mask,'DD-MON-RRRR');
         
         if :XXONT_CREDITP_HEADERS.START_DATE IS NOT NULL THEN     
              IF trunc(:XXONT_CREDITP_HEADERS.START_DATE) < trunc(:XXONT_CREDITP_HEADERS.END_DATE) THEN
                   ALERT_BUTTON1 := show_alert('INVALID_DATE');
              End If;
         end if;
    end ;
  • 4. Re: Date Validation Issue
    amit srivastava Newbie
    Currently Being Moderated
    Hello Craig,

    Now I am able to validate the date ... but still I can save END date if it is less before start date. How can I make prevent SAVE if end date is before start date?

    Thanks.
  • 5. Re: Date Validation Issue
    tony.g Journeyer
    Currently Being Moderated
    Hi

    As Craig said, you want ssomething like:

    If start_date is not null and end_date is not null then
    if start_date > end_date then
    alert .... error situation
    end if;
    end if;


    You seem to have the test the wrong way round in your code.

    Also do not trunc the dates as you will loose the time element, unless that is what you wanted to do.

    rgds
    Tony
  • 6. Re: Date Validation Issue
    amit srivastava Newbie
    Currently Being Moderated
    Hello Tony,

    Now I am able to validate the date ... but still I can save END date if it is less before start date. How can I make prevent SAVE if end date is before start date?


    Thanks.
  • 7. Re: Date Validation Issue
    HamidHelal Guru
    Currently Being Moderated
    Amit1cs wrote:
    Hello Craig,

    Now I am able to validate the date ... but still I can save END date if it is less before start date. How can I make prevent SAVE if end date is before start date?

    Thanks.
    Add RAISE FORM_TRIGGER_FAILURE; after your code. or stop the user before commiting the form at pre-commit or on-commit form level trigger.

    Hope this helps

    Hamid
  • 8. Re: Date Validation Issue
    CraigB Guru
    Currently Being Moderated
    Well, your code just tells the user the date is bad - it doesn't fail the form to prevent saving. Add "RAISE Form_Trigger_Failure" to your code after you display the Alert. For example:
    declare
      ALERT_BUTTON1 number;
    Begin
      -- set_item_property(:XXONT_CREDITP_HEADERS.END_DATE,format_mask,'DD-MON-RRRR');
      if :XXONT_CREDITP_HEADERS.START_DATE IS NOT NULL THEN 
        IF trunc(:XXONT_CREDITP_HEADERS.START_DATE) < trunc(:XXONT_CREDITP_HEADERS.END_DATE) THEN 
          ALERT_BUTTON1 := show_alert('INVALID_DATE');
          RAISE Form_Trigger_Failure;
        End If;
      end if;
    end ;
    Craig...

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points