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