CodeIgniter Forums
If date is == 0000-00-00 question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: If date is == 0000-00-00 question (/showthread.php?tid=68054)



If date is == 0000-00-00 question - wolfgang1983 - 05-18-2017

I have this code on my controller which get the users date of birth. It should show nothing if the date is 0000-00-00 from database but for some reason if not set then shows 01-01-1970

How can I make sure that if the date says 0000-00-00 on database then it will go to this $data['dob'] = '';

PHP Code:
if ($this->input->post('dob')) {
    
$data['dob'] = $this->input->post('dob');
} elseif (!empty(
$user_info)) {
    
$data['dob'] = date("d-m-Y"strtotime($user_info['dob']));
} else {
    
$data['dob'] = '';




RE: If date is == 0000-00-00 question - Rufnex - 05-18-2017

You can do a conditional check like

if(strtotime($user_info['dob']) == 0)

or

$data['dob'] = (strtotime($user_info['dob']) == 0) ? '' : date("d-m-Y", strtotime($user_info['dob']));


RE: If date is == 0000-00-00 question - wolfgang1983 - 05-18-2017

(05-18-2017, 12:40 AM)Rufnex Wrote: You can do a conditional check like

if(strtotime($user_info['dob']) == 0)

or

$data['dob'] = (strtotime($user_info['dob']) == 0) ? '' : date("d-m-Y", strtotime($user_info['dob']));

Thank you did this


PHP Code:
(!empty($user_info) && strtotime($user_info['dob']) > 0