使用strtotime()和date()更改日期时间格式时,空值导致特定日期时间

I am converting this '29-08-2013 12:27:04' datetime to this format '2013-08-29 12:27:04' using this code

$insert_dts = date('Y-m-d H:i:s',strtotime($this->input->post('insert_dts')));

But the problem is; whenever the value goes null it results in '1970-01-01 00:00:00'.

Since I am using the $insert_dts to enter into the db it was entering this value(1970-01-01 00:00:00) rather than '0000-00-00 00:00:00' in a datetime field in mysql db.

I know this can be solved with a if else checking whether the $this->input->post('insert_dts') was null or not.

Is there any other solution without checking each one?

$time = strtotime($this->input->post('insert_dts'));
if($time == 0)
$insert_dts = date('Y-m-d H:i:s',);

Using a trigger BEFORE INSERT could be a much cleaner way.

http://dev.mysql.com/doc/refman/5.0/fr/create-trigger.html

Not sure you consider it different from "checking each one".

As simple as:

$insert_dts = $this->input->post('insert_dts') ? date('Y-m-d H:i:s', strtotime($this->input->post('insert_dts'))) : '0000-00-00 00:00:00';