php - empty date goes into database as 1970/01/01 -
so have database column date, when user leaves section blank , updates record saves in database 1970/01/01.
now when make columng null = no , default = none not work.
in code check see if value null (which why strtotime() function fails). if null try set value saved ''.
$nicedate = $this->judgement_date; $databasedate = date("y-m-d", strtotime($nicedate)); if(is_null($databasedate)){ $databasedate == ''; } $this->judgement_date = $databasedate;
is there anyway me save empty value of '' in field or date type mean has have value of date format?
assuming $this->judgement_date
in a valid date format, $databasedate
never null in code strtotime()
, date()
return values (including false
). need check if $nicedate
has valid value , use empty string if not.
you use ==
instead of =
assignment operator logical error php not report.
$nicedate = $this->judgement_date; if(empty($databasedate)){ // null empty $databasedate = ''; } else { $databasedate = date("y-m-d", strtotime($nicedate)); } $this->judgement_date = $databasedate;
Comments
Post a Comment