Hello. I'm trying to use gform_save_field_value to save a date from a datepicker field (formatted d/m/Y) into iso format (Y-m-d). My original code is:
add_filter("gform_save_field_value", "save_iso_date", 2, 9);
function save_iso_date($value, $lead, $field, $form) {
list($day, $month, $year) = explode("/", $value);
return sprintf('%s-%s-%s', $year, $month, $day);
}
So, for a date given in the datepicker as 06/05/2013, this adds the value in the database as '--2013-05-06' for instance. If I replace '%s-%s-%s' with something like '%s/%s/%s' it results in '//2013-05-06'. If I drop the first two characters like so:
return substr(sprintf('%s-%s-%s', $year, $month, $day), 2);
then what's added to the db is the original string 06/05/2013. Something weird is happening. Am I going about this the right way?