Skip to main content
Participating Frequently
Mar 9, 2020 7:27 PM UTC
Answered

Simple date check based on user input

Hi all

I've spent 3 days going through various posts and communities and am still stuck.  It's not a difficult problem, but for some reason I cannot figure it out (I blame Daylight Savings Time LOL).

 

I'm using Adobe Acrobat DC and have two dates - Referral Date (ref_date) and Decision to Treat Date (dec_to_treat_date).  All I want is a message (date_message) to show on the form if the Decision to Treat is greater than Referral Date.  Here's my code at the moment, which is in my ref_date field as an ON BLUR action.  For some reason, if I put the two dates in as the same month, it works, but if I put the dates in as different months, nothing happens.  I've tried the Debugger without luck and as I'm brand new to JS, have no idea what other things I should look for.

Any ideas or suggestions would be greatly appreciated.  

Chris 

var d1 = this.getField("dec_to_treat_date").value; 
var d2 = this.getField("ref_date").value; 
var dm = getField("date_message");
if(d1 > d2)
{
dm.display = display.visible; 
}
else
{
dm.display = display.hidden; 
}

 

    try67
    try67Correct answer
    Community Expert
    Mar 10, 2020 7:52 PM UTC

    Thanks @try67 - you're comment about the date formatting poked my brain and after some additional googling I found the scand stuff.  

    One other question if i may - how do i test if a DATE field (ref_date) is not null?  I've tried !== null, != null, != "", !== "", ref_date.value.length >0, etc. and nothing's working.  FWIW, I have debugged and found that the var dateReferral = util.scand("dd-mmm-yyyy", d2);  line gets populated with today's date if ref_date doesn't have anything, but even when I refer back explictly to ref_date it still doesn't seem to recognise that the field is empty

    Have a great afternoon and thanks again 🙂


    Use valueAsString instead of value and then use !="" to check if it's not empty.

    9 replies

    DarqRoze293
    Participant
    May 13, 2025 1:30 PM UTC

    My brain has gone to the dogs! LMAO! I was thinking decision to treat was whether or not to give a dog a treat. But thank you for posting your full code later in the thread. I found it useful. 🙂

    Translate
    try67
    Community Expert
    Community Expert
    Mar 9, 2020 7:52 PM UTC

    It doesn't work because that's not how you compare dates in JavaScript.

    What is the format of your date fields?

    Translate
    Participating Frequently
    Mar 10, 2020 11:02 AM UTC

    Hi @try67 - they're in dd-mmm-yyyy format.  I can't find the link right now but the structure of the code was posted as a response to a SO question, so I guess that was misinformation.  Appreciate you taking the time to help!

    Chris

    Translate
    try67
    Community Expert
    Community Expert
    Mar 10, 2020 11:07 AM UTC

    OK. Next question is what should happen if one (or both) of the fields is empty?

    Translate