Skip to main content
Participating Frequently
March 9, 2020
Answered

Simple date check based on user input

  • March 9, 2020
  • 2 replies
  • 1037 views

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; 
}

 

    Correct answer try67

    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.

    2 replies

    DarqRoze293
    Participant
    May 13, 2025

    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. 🙂

    try67
    Community Expert
    Community Expert
    March 9, 2020

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

    What is the format of your date fields?

    Participating Frequently
    March 10, 2020

    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

    try67
    Community Expert
    Community Expert
    March 10, 2020

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