Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
protected function _convert_date_to_sql_date($date)
{
$date = substr($date,0,10);
if(preg_match('/\d{4}-\d{2}-\d{2}/',$date))
{
//If it's already a sql-date don't convert it!
return $date;
}elseif(empty($date))
{
return '';
}
$date_array = preg_split( '/[-\.\/ ]/', $date);
if($this->php_date_format == 'd/m/Y')
{
$sql_date = date('Y-m-d',mktime(0,0,0,$date_array[1],$date_array[0],$date_array[2]));
}
elseif($this->php_date_format == 'm/d/Y')
{
$sql_date = date('Y-m-d',mktime(0,0,0,$date_array[0],$date_array[1],$date_array[2]));
}
else
{
$sql_date = $date;
}
return $sql_date;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment