Reputation: 37
i want to select data from ms access using php here is my code :
$dbdir = "D:\payroll2\ATT2000.MDB";
$conn = odbc_connect("DRIVER=Microsoft Access Driver (*.mdb);DBQ=$dbdir",
"administrator",
"");
$b = 4104;
$jo = date('n/j/Y h:i:s A',strtotime('2016-01-21 00:00:01'));
$ji = date('n/j/Y h:i:s A',strtotime('2016-01-21 23:59:59'));
$sql = "SELECT TOP 20 * from CHECKINOUT inner join USERINFO on CHECKINOUT.USERID = USERINFO.USERID where USERINFO.SSN = '$b'";
$rs = odbc_exec($conn,$sql);
odbc_fetch_row($rs, 0);
while (odbc_fetch_row($rs)) {
echo odbc_result($rs,"CHECKTIME"); print('<br>');
}
odbc_close($conn);
}
it works fine , but i want to select data between two dates
so i add AND CHECKINOUT.CHECKTIME between '$jo' and '$ji'
into the query like this :
$sql = "SELECT TOP 20 * from CHECKINOUT inner join USERINFO on CHECKINOUT.USERID = USERINFO.USERID where USERINFO.SSN = '$b' AND CHECKINOUT.CHECKTIME between '$jo' and '$ji'";
i dont know why it doest work, im sure the data is exist and my date format was persist like the ms access date format.
any help will appreciated, im sorry for my bad english..
Upvotes: 0
Views: 896
Reputation: 33813
With MSAccess & MS SQL Server also I believe you need to use hash signs around the dates and you might also need to use CDate()
to ensure the date is recognised as a date.
$sql = "SELECT TOP 20 * from CHECKINOUT
inner join USERINFO on CHECKINOUT.USERID = USERINFO.USERID
where USERINFO.SSN = '$b' AND CDate( CHECKINOUT.CHECKTIME ) between '#{$jo}#' and '#{$ji}#'";
Upvotes: 3