Skip to content

Instantly share code, notes, and snippets.

@ramseyp
Created January 17, 2012 20:31
Show Gist options
  • Save ramseyp/1628714 to your computer and use it in GitHub Desktop.
Save ramseyp/1628714 to your computer and use it in GitHub Desktop.
convert gravity form date and time inputs to unix datetime
<?php
/*
* Takes a gravity form's date field & converts it to unix date/time format by populating a hidden field
*
*/
add_action('gform_pre_submission','s25_format_combstartdate');
function s25_format_combstartdate($form){
//submission form uid is 1
if($form["id"] != 1)
return;
//start date field id is 3
$date_start = $_POST["input_3"];
//start time field id is 2
$time_start = $_POST["input_2"];
$hour_start = str_pad($time_start[0], 2, "0", STR_PAD_LEFT); //making sure hour has 2 digits
$minute_start = str_pad($time_start[1], 2, "0", STR_PAD_LEFT); //making sure minutes has 2 digits
//formatting unix datetime
$raw_start_date = "{$date_start} {$hour_start}:{$minute_start} {$time_start[2]}";
$formatted_start_date = gmdate("Y-m-d H:i:s", strtotime($raw_start_date));
//hidden field for combined start date-time uid is 19
$_POST["input_19"] = $formatted_start_date;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment