我在数据库中有日期时间数据,并且从我计算的总时数只计算日期而不是时间。 我正在使用strtotime进行计算。例如:
$LastDate = '2016-04-27 17:27:28';
$endDate = strtotime($LastDate); // 1461770848
$LastDate = '2016-04-27';
$endDate = strtotime($LastDate); // 1461708000
我只想要第二个值。 所以我想从$ LastDate中提取日期。
///////////Getting data from Employee Outstation(Travel) details from database/////////////
$employeeTravel = new EmployeeTravelRecord();
$TravelEntryList = $employeeTravel->Find("employee = 2 and (date(travel_date) <= ? and ? <= date(return_date))",array($req['date_end'],$req['date_start']));
$startdate = $req['date_start'];
$enddate = $req['date_end'];
foreach($TravelEntryList as $Travelentry){
$key = $Travelentry->employee;
if($startdate >= $Travelentry->travel_date)
{
$firstdate = $startdate;
}
else
$firstdate = $Travelentry->travel_date;
if($enddate <= $Travelentry->return_date )
{
$lastdate = $enddate;
}
else
$lastdate = $Travelentry->return_date;
$holidays = $this->getholidays($firstdate,$lastdate);
$totalhours = $this->getWorkingDays($firstdate,$lastdate,$holidays);
$amount = $totalhours;
}
private function getWorkingDays($FirstDate,$LastDate,$holidays){
$endDate = strtotime($LastDate); //Here i want to give only date not the time
$startDate = strtotime($FirstDate);
$days = ($endDate - $startDate) / 86400 + 1;
$no_full_weeks = floor($days / 7);
$no_remaining_days = fmod($days, 7);
//Im doing even and odd saturday calculations....finally...
$workinghours = $workingDays*9 + $no_saturdays*7;
return $workinghours;
}
答案 0 :(得分:0)
这样的表达式可以提供所需的结果
echo strtotime('midnight', strtotime('2016-04-27 22:11')); // 1461715200
echo strtotime('2016-04-27'); // 1461715200