Skip to main content
Participating Frequently
October 25, 2019
Answered

Attempting to create a box that automatically displays the Julian date of this year.

  • October 25, 2019
  • 2 replies
  • 4716 views

I have a form that has a calendar that auto-populates a small calendar based on the selection of the first day.  I need to also display the Julian date (of that year) next to it.  Ideally, the code would read the first selected date, add the appropriate number of days to match the applicable calendar date, and then display the Julian date.  I have attached a picture for reference.  The Monday block is the manual selection and the rest update automatically based on the selection.  Any help would be greatly appreciated.

 

 

    This topic has been closed for replies.
    Correct answer try67

    Check the JS Console (Ctrl+J) for error messages.


    I tried the code above and got the following error message:

    TypeError: oMyDate.getDayOfYear is not a function

    I believe that not all versions of Acrobat support adding methods to the native objects (like Date), so if you're getting the same result try this code, instead:

     

    // define getDayOfYear function
    function getDayOfYear(d) {
    	var j1= new Date(d);
    	j1.setMonth(0, 0, 0, 0, 0, 0);
    	return Math.round((d-j1)/(1000 * 60 * 60 * 24));
    }
    
    event.value = ""; // clear field
    var cMyDate = this.getField("MyDate").valueAsString;
    if(cMyDate != ""){
    	var oMyDate = util.scand("d-mmm-yyyyy", cMyDate);
    	if (oMyDate!=null) event.value = getDayOfYear(oMyDate);
    }

    2 replies

    Participating Frequently
    October 29, 2019

    Thanks for all the help everyone!  I got it working flawlessly now, I seriously couldn't have done it without your help.

    Legend
    October 25, 2019

    I don’t see an Julian dates?

    Participating Frequently
    October 25, 2019

    I already have the box there (read only, that's why it can't be seen to the right of the date) but am missing the code for it to auto-fill.

    try67
    Community Expert
    try67Community ExpertCorrect answer
    Community Expert
    October 26, 2019

    Check the JS Console (Ctrl+J) for error messages.


    I tried the code above and got the following error message:

    TypeError: oMyDate.getDayOfYear is not a function

    I believe that not all versions of Acrobat support adding methods to the native objects (like Date), so if you're getting the same result try this code, instead:

     

    // define getDayOfYear function
    function getDayOfYear(d) {
    	var j1= new Date(d);
    	j1.setMonth(0, 0, 0, 0, 0, 0);
    	return Math.round((d-j1)/(1000 * 60 * 60 * 24));
    }
    
    event.value = ""; // clear field
    var cMyDate = this.getField("MyDate").valueAsString;
    if(cMyDate != ""){
    	var oMyDate = util.scand("d-mmm-yyyyy", cMyDate);
    	if (oMyDate!=null) event.value = getDayOfYear(oMyDate);
    }