0
我有一項任務是從經驗大於或等於2年的表中獲取員工列表。我使用表employee
中的'joined_date'
字段。使用cakephp框架。您可以告訴我提取細節的方法。提前感謝。存儲在數據庫中的當前日期和日期之間的Mysql日期差異
我有一項任務是從經驗大於或等於2年的表中獲取員工列表。我使用表employee
中的'joined_date'
字段。使用cakephp框架。您可以告訴我提取細節的方法。提前感謝。存儲在數據庫中的當前日期和日期之間的Mysql日期差異
您首先需要使用各種方法之一連接到數據庫。然後使用SQL來獲取記錄。
假設字段joined_date是一個時間戳,並且在一個表稱爲僱員 ...
下面是使用odbc_connect一個例子...
<?php
// Connect to the database
$conn = odbc_connect($server ,$username ,$password);
// Define the query
$query = "
SELECT * FROM employee
WHERE joined_date >= now() - INTERVAL 2 YEAR
";
// Execute the query and assign the results to a resource
$res = odbc_exec($conn,trim($query));
// Loop through the results
while($row = odbc_fetch_array($res))
{
print_r($row);
}
// Close the connection
odbc_close($conn);
?>
請參閱「datediff」 [頁](http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html)。它會計算日期之間的差異。 – 2013-03-01 17:18:56