Skip to content

Instantly share code, notes, and snippets.

Created January 17, 2012 20:31
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
convert gravity form date and time inputs to unix datetime
* Takes a gravity form's date field & converts it to unix date/time format by populating a hidden field
function s25_format_combstartdate($form){
//submission form uid is 1
if($form["id"] != 1)
//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