5 Replies Latest reply on May 12, 2015 8:15 AM by SteveMartino

# Calculating end date, given start date, start time, end time

### Title

Calculating end date, given start date, start time, end time

### Post

I thought I'd be able to think through this, but I keep getting stuck. I have a need to enter in a start date, start time, and end time. Then based on the elapsed time between the start time and end time, calculate the end date and stick it in a date field.

I  want the user to be able to just enter in start, and end times (or pick from a list), and pick a start date.

Example: event begins at 9pm on 5/9/2015. Event is scheduled to end at 1AM. I don't want the user to have to enter in the end date. I just want the system to handle it. Can you add elapsed time to a date to get a another date?

• ###### 1. Re: Calculating end date, given start date, start time, end time

Why don't you want the user to enter the end date?  It raises some questions/problems:

1.  Can the end date be on the same day?  Event begins at 9am.  If user puts in 10am, how would you determine if its the same day or the next day?

2.  Can the end date be the next day (as in the example)?

3.  Can the end date be more then one day later?  Start time is Monday 9 pm, and the user puts in 1am, but the actual end time is Wednesday at 1am.

Easiest would be to pick a start date/time and a duration, then the calc is easy

• ###### 2. Re: Calculating end date, given start date, start time, end time

Assuming your time field is of time data type and Date fields are date data type:

Set the "End Date" field Auto-Entry option "Do not replace" to unchecked and Calculation as :

if( Start time > End Time; Start Date+1; Start Date )

As Steve mentioned, this assumes the events do not run for more than 24 hours.

• ###### 4. Re: Calculating end date, given start date, start time, end time

I changed what I have the user enter slightly, so that it was easier (to me anyway) to calculate the end date. Instead of having the user enter the end time, I have the user enter the length (in hours, number data type) of the event.

So, the user picks a start date, start time, enters length in hours

Then end date is calculated with this: Timestamp ( date_gig_start ; time_start ) + (length_hours*3600)

Basically, I converted the start date, and start time into a Timestamp, then added the hours*3600 to get an end timestamp. And display it as a date.

This may be convoluted, but it works, and I understand it. :)

• ###### 5. Re: Calculating end date, given start date, start time, end time

That's what I did in the sample file.  Hopefully if there is an easier way someone will chime in.