Adobe Community
Turn on suggestions Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
Showonly | Search instead for
Did you mean:
- Global community
- Language:
- Deutsch
- English
- Español
- Français
- Português
- 日本語コミュニティ
Dedicated community for Japanese speakers
- 한국 커뮤니티
Dedicated community for Korean speakers
Exit
- Home
- Acrobat
- Discussions
- I need the number of days between two dates in PDF...
-
- Home
- Acrobat
- Discussions
- I need the number of days between two dates in PDF...
New Here ,
/t5/acrobat-discussions/i-need-the-number-of-days-between-two-dates-in-pdf-form/td-p/14854772 Sep 11, 2024 Sep 11, 2024
Copy link to clipboard
Copied
Have attempted to generate the number of days between two dates using a custom calculation in a text field form and no matter what formula I use the field blank.
Can anyone help?
TOPICS
Create PDFs , JavaScript , PDF , PDF forms
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
2 Correct answers
Community Expert , Sep 11, 2024 Sep 11, 2024
Nesa Nurani • Community Expert , Sep 11, 2024 Sep 11, 2024
I assume you have two dates fields and want to show number of days in 3rd field, let's say two dates fields are named "Date1" and "Date2", use this as custom calculation script of 3rd field:
var date1 = this.getField("Date1").valueAsString;var date2 = this.getField("Date2").valueAsString;if (date1 && date2) { var d1 = new Date(date1); var d2 = new Date(date2); var diffInMs = d2.getTime() - d1.getTime(); var diffInDays = diffInMs / (1000 * 60 * 60 * 24); event.value = diffInDays.toFix
...
Votes 1 Upvote
Translate
Translate
Jump to answer
Community Expert , Sep 11, 2024 Sep 11, 2024
Nesa Nurani • Community Expert , Sep 11, 2024 Sep 11, 2024
Here you go:
var date1 = this.getField("Date1").valueAsString;var date2 = this.getField("Date2").valueAsString;if (date1 && date2) { var d1 = new Date(date1); var d2 = new Date(date2); var year1 = d1.getFullYear(); var year2 = d2.getFullYear(); var month1 = d1.getMonth(); var month2 = d2.getMonth(); var diffInMonths = (year2 - year1) * 12 + (month2 - month1); event.value = diffInMonths;} else { event.value = "";}
Votes Upvote
Translate
Translate
Jump to answer
4 Replies 4
Jump to latest reply
Community Expert ,
/t5/acrobat-discussions/i-need-the-number-of-days-between-two-dates-in-pdf-form/m-p/14854845#M478394 Sep 11, 2024 Sep 11, 2024
Copy link to clipboard
Copied
I assume you have two dates fields and want to show number of days in 3rd field, let's say two dates fields are named "Date1" and "Date2", use this as custom calculation script of 3rd field:
var date1 = this.getField("Date1").valueAsString;var date2 = this.getField("Date2").valueAsString;if (date1 && date2) { var d1 = new Date(date1); var d2 = new Date(date2); var diffInMs = d2.getTime() - d1.getTime(); var diffInDays = diffInMs / (1000 * 60 * 60 * 24); event.value = diffInDays.toFixed(0);} else { event.value = "";}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jerry_Owens4329 AUTHOR
New Here ,
/t5/acrobat-discussions/i-need-the-number-of-days-between-two-dates-in-pdf-form/m-p/14855113#M478418 Sep 11, 2024 Sep 11, 2024
Copy link to clipboard
Copied
Perfect it works!
Is there a Java script to count months between two dates.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Expert ,
/t5/acrobat-discussions/i-need-the-number-of-days-between-two-dates-in-pdf-form/m-p/14855531#M478439 Sep 11, 2024 Sep 11, 2024
Copy link to clipboard
Copied
Here you go:
var date1 = this.getField("Date1").valueAsString;var date2 = this.getField("Date2").valueAsString;if (date1 && date2) { var d1 = new Date(date1); var d2 = new Date(date2); var year1 = d1.getFullYear(); var year2 = d2.getFullYear(); var month1 = d1.getMonth(); var month2 = d2.getMonth(); var diffInMonths = (year2 - year1) * 12 + (month2 - month1); event.value = diffInMonths;} else { event.value = "";}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jerry_Owens4329 AUTHOR
New Here ,
/t5/acrobat-discussions/i-need-the-number-of-days-between-two-dates-in-pdf-form/m-p/14856216#M478486 Sep 12, 2024 Sep 12, 2024
Copy link to clipboard
Copied
LATEST
Thank you so much!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Resources
About Adobe Acrobat
Adobe Inc
Whats new in Acrobat DC
Adobe Inc
Plan and Pricing
Adobe Inc
Adobe Acrobat features and tools
Adobe Inc
Adobe Acrobat Feature & Workflow
Edit PDFs
Edit Scanned PDFs
PDF Forms
Sign a PDF
FAQs
How to Edit Scanned or Secured document
Rotate | move | delete and renumber PDF pages
Acrobat download and installation help
Copyright © 2024 Adobe. All rights reserved.
Using the Community Experience League Terms of Use Privacy Cookie preferences Do not sell or share my personal information AdChoices