skip to Main Content

I used to get today’s record from MySQL database. I used this code:

$whr_follow = "(DATE(R.reg_time) = Date(NOW()) )" ;
$this->db->where($whr_follow);

Today is march 1st, but I get yesterdays. In local server it works fine.
I tried select now() query in phpmyadmin.

In live server it resulted 2019-02-28 23:30:36 but in local server its 2019-03-01 10:59:14

I tried to change phpmyadmin timezone win phpmyadmin running set timezone=timezone (asia/kolkatha) but makes no changes.Any idea?

4

Answers


  1. change the time zone on your live server, because your live server is late, not your local server.

    hope this helps!

    Login or Signup to reply.
  2. First, make sure both local and live server have the same time zone.

    Second, make sure your input and the date format in the DB should be same

    $current_date = date('Y-m-d', strtotime('now')) //Current date
    

    Make other date format same as well

    Login or Signup to reply.
  3. first get current date.i hope it will help you.

    $date = new DateTime("now");
    
     $curr_date = $date->format('Y-m-d ');
    
     $this->db->select('*');
     $this->db->from('tablename'); 
     $this->db->where('DATE(Date)',$curr_date);//use date function
     $query = $this->db->get();
        return $query->result();
    
    Login or Signup to reply.
  4. =>You get Current Date and then change your date Formate "Y-m-d" same as a database date format.

    $date = new DateTime("now");
    
    $currDate = $date->format('Y-m-d ');
    
     $this->db->select('*');
     $this->db->from('Table Name'); 
     $this->db->where('DATE(Date)',$currDate);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search