Reputation: 69
In my form i have date field but not mandatory(require) when someone forget to fill the date field it get 01/01/1970 by default in database , it not good , i want when it happens it show no date selected i am using this function but its not working any help
<?php
function getDateFormat($date){
if($date == '0000-00-00'){
return 'No Date Selected.';
}
else {
return date('d-m-Y',strtotime($date));
}
}
?>
Upvotes: 1
Views: 5793
Reputation: 10121
Change your value in if
condition, and also set allow in DB to NULL
if($date == '0000-00-00'){
return NULL;
}
Upvotes: 0
Reputation: 1698
Maybe your date field is a datetime
. Try with
if($date == '0000-00-00 00:00:00')
Upvotes: 0
Reputation: 1135
Allow Null to date field in database. And also you can set default value for date field.
Upvotes: 2
Reputation: 1761
Try replacing
if($date == '0000-00-00')
with
if($date == '0000-00-00' || $date == NULL)
Upvotes: 0