diff --git a/form.php b/form.php index 78150e2..dc6ddfc 100644 --- a/form.php +++ b/form.php @@ -301,6 +301,24 @@ class form } return $errors; } + + /** Convert Date received in one format to another. + * If the provided string is not corresponding to the format, don't change + * anything. + * Format used http://php.net/manual/en/datetime.createfromformat.php + * @param string $inputDate + * @param string $inputFormat + * @param string $outputFormat + * @return string + */ + public function convertDate ($inputDate, $inputFormat, $outputFormat) + { + $date = DateTime::CreateFromFormat ($inputFormat, $inputDate); + $errors = $date->getLastErrors(); + if ($errors["warning_count"] > 0 || $errors["error_count"] > 0) + return $inputDate; + return $date->format ($outputFormat); + } } /** the definition of a formfield */