# Add hours to date/time

**academicproofreading**Hello!

I'm trying to use the calculation field to add 12 hours to a date/time field. If, for example, a client types a certain number into a field, I want the return date to be today's date and time with 12 hours added on. I can get it working for adding whole days on (I have a hidden date/time field and I pull this info and use the calculation field to add the days and then output this to a new field), but I can't seem to get the same thing to work for adding hours. Any ideas?

Many thanks.

- JotForm Support
**BJoanna**I did some test and unfortunately I was also not able to pass values from one time field to another time field.

Possible workaround would be to pass value from time field to text box field and to add 12 hours.

Here is my demo form: https://form.jotform.com/53431002750946?

Hope this will help. Let us know if you need further assistance.

**academicproofreading**Thanks for trying but this does not work unfortunately. Adding hours like that won't change the days. So if the date/time is 10/12/15 and 23:00, I want to add 12 hours to make it 11/12/15 and 11:00, but using your method will keep the day as 10/12/15 and make the time 38:00.

Any other ideas?

Thank you for your help.

**Charlie**I'm not sure if this is possible. I do have a workaround in mind, but please do allow be some time to formulate and test it in my end. I will get back to you as soon as I have finished it.

**academicproofreading**Thank you! I look forward to hearing from you.

**Charlie**See if this form works for you: https://form.jotform.com/53434266107957?.

It will get the current date and time to when the form is opened and will output a date and time that is 12 hours from your current date and time. However, this will only work for 24 hour format.

If that form works, please let me know and I'll list down the steps. You can also clone my form to see how it was setup. Here's a guide on how to clone it: http://www.jotform.com/help/42-How-to-Clone-an-Existing-Form-from-a-URL

We'll wait for your response.

**academicproofreading**That works perfectly! Thanks! I would be grateful if you could list your steps. Many thanks.

**Charlie**You are welcome. You can follow the steps below, but I would recommend cloning my form so that you can use it as a reference. The step is quite long, but I hope this will help.

1. This is how mine is structured or setup:

"Date" - Gets the current date

"Time" - Gets the current time (24 hour format)

"Output Time" - Gets "Time" value + 12 hours.

"Hours" - Get the hour value on the "Output Time".

"Minutes" - Get the minutes value on the "Output Time".

"Date Output" - Outputs the date after adding 12 hours.

"Date and Time (+12 hours)" - The final date and time after 12 hours.

2. In the "Output Time", I'm using the Form Calculation widget, we fetch the "Time" value and add 12 on it.

3. Now in the "Hours" field, we want to get the hour value WITHOUT the minutes.

To do this we will set up conditions.

Condition 1: This means adding 12 hours moves the date on another day (24 hours in one day). We will use the math function "floor()" to NOT round off, but only to remove the minutes. We will subtract it to "24" so that we can get the next days hour value.

*IF "Output Time" is greater than "24"**Then**floor("Output Time) - 24 hours to "Hours"*You can get the math function "floor()" when you click the "..." button.

Condition 2: This means adding 12 hours did not move the date on the next day so no need to subtract anything, we will however use the "floor()" function to remove the minutes.

*IF "Output Time" is equal to "24" OR less than "24"**Then**floor("Output Time") to "Hours"*This is how they look like in the Conditions.

4. Now we want to get the "Minutes" value, this is the decimal integer in the "Output Time". This is quite tricky. I'll use a form calculation widget here, the formula would be:

round(("Output Time" - floor("Output Time"))*60)

Example:

=round((30.83 - floor(30.83))*60)

=round((30.83 - 30) * 60)

=round(0.83 * 60)

=round(49.8)

=50 minutes

Please make sure that you are placing the brackets correctly.

5. Now we will go to the "Date Output" field, here's my conditions for it. Basically, this is somewhat the same with "Hours", we will identify if the day needs to move on the next day if the "Output Time" is greater or less than or equal to 24.

Below is an example of the condition, I will fetch the "Date" field and add one on it if the "Output Time" is greater than 24.

6. Now we all have the elements, we have the date, the hour and the minutes. We will then just need to concatenate them. I will output them using the Form Calculation widget.

Here, just add the fields "Date Output", "Hours" : "Minutes".

Make sure that they are set to "a-z", this means they will have the text string value, if you are seeing "0-9", just click on it to change it to "a-z".

If you have questions or concerns, just let me know and we will glad to be of help.