Skip to main content
Participant
August 28, 2020
Answered

Adobe Pro Javascript Datepicker - If within 30 days from today

  • August 28, 2020
  • 3 replies
  • 723 views

Hello all, I'm not a javascript coder by any stretch, but I do understand coding... I'd like, if someone is willing, to help be with a script that changes a datepicker (dp1) strokeColor based on whether or not it's within 60 days (yellow) or 30 days (red) from today - all using the format yyyymmdd (in the Army lol)

 

For example, today is 20200827 and if the date selected is 20201005 then the border of the date picker would turn yellow...

 

Lastly, a button that would update/refresh the datepicker to ensure it was still accurate strokeColor..

 

Apologies for not having a working solution, I'm a noob...

This topic has been closed for replies.
Correct answer try67

Assuming that black, you can use this code as the field's custom calculation script:

 

var customStrokeColor = color.black;
var s = event.value;
if (s) {
	var d = util.scand("yyyymmdd", s);
	var now = new Date();
	var diff = d.getTime()-now.getTime();
	var diffInDays = Math.floor(diff/86400000);
	if (diffInDays<30) customStrokeColor = color.red;
	else if (diffInDays<60) customStrokeColor = color.yellow;
}
event.target.strokeColor = customStrokeColor;

 

In order to update it when the file is opened add the following command under Tools - JavaScript - Document JavaScripts (NOT inside a function!):

 

this.calculateNow();

3 replies

Participant
August 28, 2020

Thank you try67!! I will give it a shot in a couple hours, but I've seen your work on a lot of problems through this forum and I'm certain it's correct. I appreciate your time/help!

try67
Community Expert
Community Expert
August 28, 2020

What should it be if it's neither?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 28, 2020

Assuming that black, you can use this code as the field's custom calculation script:

 

var customStrokeColor = color.black;
var s = event.value;
if (s) {
	var d = util.scand("yyyymmdd", s);
	var now = new Date();
	var diff = d.getTime()-now.getTime();
	var diffInDays = Math.floor(diff/86400000);
	if (diffInDays<30) customStrokeColor = color.red;
	else if (diffInDays<60) customStrokeColor = color.yellow;
}
event.target.strokeColor = customStrokeColor;

 

In order to update it when the file is opened add the following command under Tools - JavaScript - Document JavaScripts (NOT inside a function!):

 

this.calculateNow();

Participant
August 28, 2020

It worked like a charm! Thank you for your time and selflessness to help me out!

Bernd Alheit
Community Expert
Community Expert
August 28, 2020

You don't need a button for update/refresh. You can change the color at document open.

Participant
August 28, 2020

I wondered about that, thank you for the insight.