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

How to get the difference between two date and time?

Contributor ,
Sep 01, 2022 Sep 01, 2022

Good day!

 

I have created a form with the following fields:

  • Start Date and Time (fieldname F01001 and F01002, respectively)
  • Finish Date and Time (fieldname F02001 and F02002, respectively)
  • Unbillable Hours (fieldname F03001)

All the dates have the format dd/mm/yyyy. Example: 01/09/ 2022 for September 1, 2022

All the times have the format hh:ss tt. Example: 2:30 for 2 hours and 30 second

 

What I want to happen is:

  1. First, validate if the Start Date and Time is less than Finish Date and Time. If valid, it should proceed to step b). Otherwise, it should displace a message to correct the data with an “OK” to exit from that message.

2. Then get the difference between the Start Date and Time and Finish Date and Time. Results should be the number of hours with 1 decimal place.

3. Subtract the Unbillable Hours from the Step 2 result.

 

Example:

Start Date and Time = 31/08/2022 10:00 pm

Finish Date and Time = 01/09/2022 06:30 am

Unbillable Hours = 2 hours

 

If I compute this manually, it would be 7.5 Hours less 2 unbillable hours equals 5.5 hours.

 

How do I do this?

 

If this cannot be done, I will be happy to have a solution if dates are not included. This means that the given are Start Time, Finish Date and Unbillable Hours.

 

Thank you in advance.

TOPICS
PDF forms
5.8K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Sep 04, 2022 Sep 04, 2022

A small error corrected!

You can remove the script of the Unbillable Hours field, but you will get an error if you enter a anything else than a number in this field.

@+

View solution in original post

Translate
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
Enthusiast ,
Sep 01, 2022 Sep 01, 2022

This can be done, and there are a lot of dates time scripts on these forums try to research a bit and then post your solution, and we will help you.

Or if it's too much for you, you can always hire someone to do it for you.

Translate
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
Contributor ,
Sep 02, 2022 Sep 02, 2022

Hi Asim123,

 

Thank you for replying.

Before I posted my question, I tried to search here for a possible solution. The problem is zero knowledge about scripting. Apology for this.

I don't mind hiring someone (as you suggested) to provide the solution to my question. I just need to know you much would it cost me and how should I be paying.

Thank you..

Translate
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 ,
Sep 02, 2022 Sep 02, 2022

Hi,
Attached is an answer to your request.

Just a remark, in your example the result must be 6.5 hours and bot 7.5!

@+

 

Translate
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
Contributor ,
Sep 03, 2022 Sep 03, 2022

Hi Bebarth,

Thank you for correcting me on my computation. You are right, the answer should be 6.5.

Appreciate the solution you have provided. This is exactly the solution I am looking for.

When I tried to substitute the fieldnames in your script with the actual fieldnames in my fillable PDF, it didn’t work. This my mistake but couldn’t figure it out what is wrong. Like I mentioned, I have zero knowledge in scripting.

I might be requesting too much from you. But would you be kind enough to help me out again? I know such a thing is too much to ask but for someone like you, this is easy.

Here are the changes I would like to so I can just do cut-and-paste the script into my fillable PDF and make the

  1. Use only one Date. Both Start Time and Finish Time would fall within this Date.
  2. Use the following fieldnames:

F02001a   Start Date (dd/mm/yyyy)

F02001d   Start Time (hh:mm tt)

F02001e   Finish Time (hh:mm tt)

  1. We can remove the text “HOURS” in both Unbillable Hours and Total Hours as there is already a column heading for these.
  2. Total Hours is the difference between the Start Time and Finish Time less Unbillable Hours.

If this is too much favor, I am willing to compensate you for your effort. Thanks.

 

Translate
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 ,
Sep 03, 2022 Sep 03, 2022

Here it is!

But in fact if start and end date are the same day, it is not used in the calculation script...

@+

 

Translate
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
Contributor ,
Sep 04, 2022 Sep 04, 2022

Hi Bebarth, 

 

Appreciate the effort you did here.

 

I downloaded Example_BB.pdf and when I tried it by entering the following:

 

Date = 02/09/2022

Start Time = 8:00 am

Finish Time = 6:00 pm

Unbillable Hours = 2

It gives me a message "The end time must be after the start time."

 

Also, is the script in Unbillable Hours under the Format tab, necessary? Can I delete that? Thanks.

Translate
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 ,
Sep 04, 2022 Sep 04, 2022

A small error corrected!

You can remove the script of the Unbillable Hours field, but you will get an error if you enter a anything else than a number in this field.

@+

Translate
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
Contributor ,
Sep 04, 2022 Sep 04, 2022

Your last solution works perfectly. I guess the problem is from my end. Appreciate the help.

 

Please let me know how I can compensate you for your effort. How much do I owe you? I have PayPal account. I can settle my outstanding through this platform. Send me this information privately as I don't think such information is allowed here or you can email me at henryfuaong@yahoo.com. Thank you.

Translate
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 ,
Sep 05, 2022 Sep 05, 2022

It's for me... 😉

@+

 

Translate
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
Contributor ,
Sep 11, 2022 Sep 11, 2022
LATEST

Thank you Bebarth for the help. I really appreciate your effort.

Translate
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