PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 15, 2022

[FIXED] How to compare only date and year in php codeigniter

 March 15, 2022     codeigniter, mysql, php     No comments   

Issue

My model:

public function get_payscale() {
    $this->db->from('payscale P')->join('employee E','E.employee_id = P.employee_id ');
    $this->db->where('P.payscale_date',date('Y-m'));
    return $this->db->get()->result_array();
}   

I want to compare only the month and year with the db, in which the format is y-m-d, where I want only to retrieve the y-m using the where clause.


Solution

Use like this :

$this->db->where('EXTRACT(YEAR_MONTH FROM P.payscale_date)',date('Ym'));

This query will extract the Year and month from the date given column like 201605 (2016-05-21)



Answered By - Aju John
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing