i have written php code match date , time matches date not able match time. have 2 tables - tbl_staff_master, timesheet.
$_get['task_dt'] - datetime. example task_dt= "07/17/2015 20:35:00"
here code.
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 tbl_staff_master sm, timesheet ts sm.scid = ts.scid , sm.is_deleted='0'"); foreach($eventdata $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 schema
-- table structure 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 ; some data in table
-- -- dumping data table `tbl_staff_master` -- insert `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 table `timesheet` -- insert `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');
Comments
Post a Comment