问题
I need to select current date from database in mm/dd/yyyy format..But php curdate() function returns date format in yyyy-mm-dd as default..How could I resolve this issue.?
My model function is:
public function get_cat($category)
{
$this->db->select('*');
if($category!='')
{
$this->db->like('Category',$category,'both');
$this->db->from('tbl_job');
$this->db->where('Expiry_date >=','DATE(CURDATE())',FALSE);
$result = $this->db->get();
}
return $result->result();
}
回答1:
Use DATE_FORMAT to format the date
DATE_FORMAT(curdate(), '%m/%d/%Y')
回答2:
use Str_to_date
Str_to_date(Expiry_date,'%m/%d/%Y')
Try this code :-
$this->db->where('Str_to_date(Expiry_date,'%m/%d/%Y') >=','DATE(CURDATE())',FALSE);
来源:https://stackoverflow.com/questions/33991851/how-curdate-function-could-return-date-in-mm-dd-yyyy-format-php