Baidyanath Prasad Baidyanath Prasad - 7 months ago 12
PHP Question

Retrieving table according to the given date range

There is table called "table_name" which have 4 columns

id | salary | emp_id | joining_date



1 | 2900 | ep4354 | 2016-04-15 11:15:18



2 | 3001 | ep7354 | 2016-04-16 07:13:01



3 | 4201 | ep7365 | 2016-04-17 08:19:32



Now I want to retrieve table from date 2016-04-16 to 2016-04-17 (ignore time). My query in laravel is-

$table = DB::select("SELECT * FROM table_name WHERE date(joining_date)>= '".$from."' AND date(joining_date) <= '".$to."'");

//where $from and $to is variable and say there values are $from =2016-04-16 and $to =2016-04-17. So it should display table with two columns as-

id | salary | emp_id | joining_date



2 | 3001 | ep7354 | 2016-04-16 07:13:01



3 | 4201 | ep7365 | 2016-04-17 08:19:32

Query is working fine, Thankful to Ankit Verma who helped me within few minutes just after putting my question. I just edited my question to those who said "Question is not clear" still after getting right answer. Although I want more better query for the same if you guys have, Please suggest me.
Thanks in advance.

Answer
    Take a look on the following query 

    SELECT * FROM `users` WHERE  date(`created_at`)='2016-04-14'
    in laravel user the following code
 $table = DB::select("SELECT * FROM users WHERE  date(created_at)='".$from."'"); 
Comments