我编写了一个PHP代码来匹配与日期匹配的日期和时间,但我无法匹配时间。有2个表 - Tbl_Staff_Master,TimeSheet。
$_GET['Task_DT'] - datetime.
示例Task_DT =" 07/17/2015 20:35:00"
这是我的代码。
function timesheetstaff(){
$result = '';
if(!empty($_GET)){
$taskdt = strtotime($_GET['Task_DT']);
$tdate = date('Y-m-d',$taskdt);
$ttime = date('H:i:s',$taskdt);
//echo $tdate." ".$ttime;
//exit(0);
$useinfo = array();
$eventData = $this->ez_db->get_results("SELECT distinct sm.*,ts.FD,ts.TD,ts.FT,ts.TT FROM Tbl_Staff_Master sm, TimeSheet ts WHERE sm.SCId = ts.SCId and sm.Is_Deleted='0'");
foreach($eventData as $row)
{
if($row->FD >=$tdate && $row->TD <=$tdate) && ($row->FT >=$ttime && $row->TT <=$ttime))
{
$useinfo['SCId'] = $row->SCId;
$useinfo['First_Name'] = $row->First_Name;
$useinfo['Last_Name'] = $row->Last_Name;
}
}
echo '{"status":true,"items":'.json_encode($useinfo).'}'; exit(0);
}
else{
echo "Invalid URL";exit;
}
}
SQL表架构
-- Table structure for table `Tbl_Staff_Master`
--
CREATE TABLE IF NOT EXISTS `Tbl_Staff_Master` (
`SCId` int(4) NOT NULL AUTO_INCREMENT,
`Cid` int(4) NOT NULL,
`First_Name` varchar(50) NOT NULL,
`Last_Name` varchar(50) NOT NULL,
`City` varchar(100) NOT NULL,
`Address` varchar(200) NOT NULL,
`Contact_No` varchar(20) NOT NULL,
`Email_ID` varchar(100) NOT NULL,
`Password` varchar(15) NOT NULL,
`SC_DT` datetime NOT NULL,
`Status` tinyint(4) NOT NULL,
`Is_Deleted` tinyint(1) NOT NULL,
`Action` int(11) NOT NULL,
`LoginSt` tinyint(1) NOT NULL,
`Token` text NOT NULL,
PRIMARY KEY (`SCId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=211 ;
CREATE TABLE IF NOT EXISTS `TimeSheet` (
`TSId` int(4) NOT NULL AUTO_INCREMENT,
`SCId` int(4) NOT NULL,
`FD` date NOT NULL,
`TD` date NOT NULL,
`FT` time NOT NULL,
`TT` time NOT NULL,
`TS_DT` datetime NOT NULL,
PRIMARY KEY (`TSId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=176 ;
表格中的某些数据
--
-- Dumping data for table `Tbl_Staff_Master`
--
INSERT INTO `Tbl_Staff_Master` (`SCId`, `Cid`, `First_Name`, `Last_Name`, `City`, `Address`, `Contact_No`, `Email_ID`, `Password`, `SC_DT`, `Status`, `Is_Deleted`, `Action`, `LoginSt`, `Token`) VALUES
(210, 25, 'Asss', 'H', 'B', 'H', '45tyi', 'hjhg', 'P@ssword123', '2015-07-16 09:27:58', 0, 0, 0, 0, '4ab21e845cb9f82f4c5beefd86fadf3989c291c0c761c74');
--
-- Dumping data for table `TimeSheet`
--
INSERT INTO `TimeSheet` (`TSId`, `SCId`, `FD`, `TD`, `FT`, `TT`, `TS_DT`) VALUES
(174, 184, '2015-07-17', '2015-07-17', '19:35:00', '20:35:00', '2015-07-14 13:05:43'),
(175, 184, '2015-07-18', '2015-07-18', '21:43:00', '22:43:00', '2015-07-14 13:13:54'),
(173, 184, '2015-07-19', '2015-07-19', '19:15:00', '20:15:00', '2015-07-14 12:46:20');