Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action("gform_pre_submission","pre_submission_handler");
- function pre_submission_handler($form) {
- // get input from form
- $date = $_POST["input_1"];
- $start = $_POST["input_11"];
- $end = $_POST["input_5"];
- // convert date and time arrays into datetime formats
- $startdate = date_create_from_format('m/d/Y@h:i a', $date . "@". $start[0].":".$start[1]." ".$start[2]);
- $enddate = date_create_from_format('m/d/Y@h:i a', $date . "@". $end[0].":".$end[1]." ".$end[2]);
- //convert datetimes into seconds to compare
- $starttime = strtotime($startdate->format('Y-m-d H:i:s'));
- $endtime = strtotime($enddate->format('Y-m-d H:i:s'));
- // check to see if the times span overnight
- if($starttime > $endtime)
- $endtime = strtotime($enddate->format('Y-m-d H:i:s') . " +1 day");
- // perform calculation
- $diff = floor(($endtime - $starttime)/60);
- $_POST["input_50"] = $diff;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement