CodeIgniter Forums
[SQL] Search for available personnel - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: General (https://forum.codeigniter.com/forumdisplay.php?fid=1)
+--- Forum: Lounge (https://forum.codeigniter.com/forumdisplay.php?fid=3)
+--- Thread: [SQL] Search for available personnel (/showthread.php?tid=72236)



[SQL] Search for available personnel - user4852 - 11-26-2018

Hi there!

I have a table with jobs in my app. 

Here it is with a from date and to date and of course the employee_id. 

I want to list everyone that is available between two dates. 

Whats the best practice for this?

Thanks.


RE: [SQL] Search for available personnel - InsiteFX - 11-26-2018

PHP Code:
SELECT *
FROM order_details
WHERE your_date 
>= CAST('2014-02-01' AS DATE)
AND 
your_date <= CAST('2014-02-28' AS DATE);


$query $this->db->where('yourDate >='$startDate)
 
                 ->where('yourDate <='$endDate)
 
                 ->get('yourTable'); 



RE: [SQL] Search for available personnel - php_rocs - 11-26-2018

@user4852

...or (https://www.codeigniter.com/userguide3/database/queries.html#query-bindings )


$sql = "SELECT * FROM order_details Where your_date >= ? and your_date <= ?";
$this->db->query($sql, array('2014-02-01', '2014-02-28'));

or If you have to cast the strings as dates...

$sql = "SELECT * FROM order_details Where your_date >= CAST(? as DATE) and your_date <= CAST(? as DATE)";
$this->db->query($sql, array('2014-02-01', '2014-02-28'));