Login using the username and password you created for AcrobatUsers.com.
Note: This is not the same as your Adobe ID.
Benefits of Free Membership:
Find out what AcrobatUsers.com is all about
You don't have to be a member to look at any content on the site. Increase your expertise with our helpful tutorials, videos, forums, and sample PDFs.
Like what you see? Take the next step and become a member. Register now to get discounts, attend eSeminars, ask questions and more.
Get the most out of your membership. Post in the forums, create your profile, submit to the gallery, attend a user group meeting. Log In now.
ANSWERED
Hello,
I have a field called HireDt that is formatted as date and mm/dd/yyyy. I want to compare HireDt with today's date and come up with YrsSvc calculated field with only the full years between.
Any help would be appreciated.
Thanks, Shawn
My Product Information:
Acrobat Standard 5 / Windows
Offline

There are plenty of tutorials on how to work with Date objects on this website. I suggest you search for them. But basically, you need to do something like this:
date = util.scand("mm/dd/yyyy",dateAsString);
difference_in_years = date.getFullYear() - (new Date().getFullYear());(edit: this will just show the difference in whole years, if you want to take the actual day into account it needs to be tweaked a bit)
Last edited by try67 (2010-02-08 18:35:07)
Offline
Ok, thanks for the response and I will try it. But, how do you get today's date?
Offline

When you create a new Date object it automatically has the current date and time.
Offline
Thank you - this almost works. I know I am probably missing something really simple here, but I entered 03/10/2000 into my HireDt field and my YrsSvc field should have come up to 9 years from today's date because we have not reached March 10th yet. But it is rounding up and I am getting 10 years instead.
This is my code.
var Hire = this.getField('HireDt').value;
date = util.scand("mm/dd/yyyy",Hire);
difference_in_years = (new Date().getFullYear()) - date.getFullYear();
event.value = difference_in_years;
Any help is appreciated.
Thanks, Shawn
Offline

ACCEPTED ANSWER
Well, like I said, the other script was not perfect, because it didn't take into account the day of the year.
This version does:
var Hire = this.getField('HireDt').value;
date = util.scand("mm/dd/yyyy",Hire);
now = new Date();
difference_in_years = (now.getFullYear()) - date.getFullYear();
if (now.getMonth()<date.getMonth()) {
difference_in_years--;
} else if ((now.getMonth()==date.getMonth()) && (now.getDate()<date.getDate())) {
difference_in_years--;
}
event.value = difference_in_years;Offline
Thank you so much, that worked perfectly! :)
Offline