• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

nth day of year script

New Here ,
May 31, 2019 May 31, 2019

Copy link to clipboard

Copied

I need a script to calculate the nth day of the year.  I would like to input a date on a form, and then have a script in a different field that takes that date and tells me the nth day of the year for the date I input in the other field.  Example: I would like to input May 31, 2019 in a date field and the in another field put on the script which would  using that date and  show the number 151 in this case.  I have searched the net and found some discussion but nothing that works in adobe. (they go on and on about time zones and leap year etc.) I just need something simple that works in adobe.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

221

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 31, 2019 May 31, 2019

Copy link to clipboard

Copied

The basic method to do it would be to create a new Date object that is the first day of the year and keep incrementing its value by one day until you read the target date, while using a counter to keep track of the number of increments. That counter is your result.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 31, 2019 May 31, 2019

Copy link to clipboard

Copied

Thanks for the input but I was hoping someone would have the exact script to use.  I have tried to do myself many times and looked on the net in several forums that discuss this issue but not found script that works in adobe. Seems that this would be simpler and would be something that would be easy to find.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 31, 2019 May 31, 2019

Copy link to clipboard

Copied

I'm happy to write the code for you, for a small fee. You can contact me privately via [try6767 at gmail.com] to discuss it further.

Alternatively, I'm happy to send you some links to resources that will help you write the code yourself, but as you've seen it's not a trivial task.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 31, 2019 May 31, 2019

Copy link to clipboard

Copied

Or, you could share your best effort, and we might be able to help you learn the skills you need to get it working.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 01, 2019 Jun 01, 2019

Copy link to clipboard

Copied

Something like this:

Adobe Document Cloud

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 01, 2019 Jun 01, 2019

Copy link to clipboard

Copied

LATEST

Another solution that could be used in other PDF by adding the following the following scripts to the document level functions for a PDF:

// document level code;

Date.prototype.isLeapYear = function() {

// determine if a year is a leap year or not;

// this crates a new property for the Date object;

// input date object;

// return 1 if a leap year 0 if not a leap year;

    var year = this.getFullYear();

    if((year & 3) != 0) return false;

    return ((year % 100) != 0 || (year % 400) == 0);

}

// Get Day of Year

Date.prototype.getDOY = function() {

// determine the day of year for a given date;

// This code creates a new propety for the dote object;

// input date object;

// returns the day of the year adjusted for leap years;

    var dayCount = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];

    var mn = this.getMonth();

    var dn = this.getDate();

    var dayOfYear = dayCount[mn] + dn;

    if(mn > 1 && this.isLeapYear()) dayOfYear++;

    return dayOfYear;

}

// end document level code;

And then the field calculation script would be:

var cNowDate = this.getField("Date").valueAsString;

var cNowFormat = "d-mmm-yyyy";

event.value = "";

if(cNowDate != "") {

cNoow = util.scand(cNowFormat, cNowDate);

event.value = oNow.getDOY();

}

One only needs to change the name of the input date field and the format for that field.

The code for the leap year method could be used in other date calculations when one needs to determine if a year is a leap year.

Note that both document level code listings create two new properties for the Date object.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines