CodeIgniter Forums

Full Version: YEAR in active record
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
HI , i have a table :

 `id` bigint(20) UNSIGNED NOT NULL,
  `data` date NOT NULL,
  `numero_settimana` int(11) NOT NULL,
  `giorno_settimanale` varchar(15) NOT NULL,
  `orari_apertura_id` int(11) NOT NULL,
  `stato_agenda_id` int(10) UNSIGNED NOT NULL COMMENT '= aperto chiuso o prenotato',
  `clienti_id` int(10) UNSIGNED DEFAULT NULL,
  `note` varchar(100) DEFAULT NULL

This is a part my function :

PHP Code:
getweek($numsettimana,$data,$tabella){

 
       $this->db->where('numero_settimana'$numsettimana);
 
       $this->db->where('giorno_settimanale''Domenica');
 
       
        $query
=$this->db->get($tabella);
 
       

But it get the row  of every years , how can i get only by year of var $data ($data have yyyy-mm-dd format) ?
Try this and see if it is what you want, not tested.

PHP Code:
$query $this->db->select('SELECT DATE("{$data}") as required_DATE')
 
             ->where('numero_settimana'$numsettimana)
 
             ->where('giorno_settimanale''Domenica')
 
             ->db->get($tabella); 
PHP Code:
function getweek($numsettimana$data$tabella){
 
   $this->db->from($tabella);
 
   $this->db->where('numero_settimana'$numsettimana);
 
   $this->db->where('giorno_settimanale''Domenica');
 
   $this->db->where("YEAR(data)""YEAR('{$data}')"FALSE);
 
   $query $this->db->get();

Hello,

I just read your question. I think you need to change the data type.

you have to need to change your field data type for 'numero_settimana' int to DATE.

Hope it will help you friend.