Extract only date from datetime for calculating total time in PHP -


i have date time data in database , im calculating total hours taking date not timing. im using strtotime calculations. ex:

$lastdate = '2016-04-27 17:27:28'; $enddate = strtotime($lastdate); // 1461770848  $lastdate = '2016-04-27'; $enddate = strtotime($lastdate); // 1461708000 

i want second value only. want extract date $lastdate .

 ///////////getting data employee outstation(travel) details database/////////////    $employeetravel = new employeetravelrecord();          $travelentrylist = $employeetravel->find("employee = 2 , (date(travel_date) <= ? , ? <=  date(return_date))",array($req['date_end'],$req['date_start']));              $startdate = $req['date_start'];             $enddate = $req['date_end'];             foreach($travelentrylist $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 want give date not time         $startdate = strtotime($firstdate);           $days = ($enddate - $startdate) / 86400 + 1;          $no_full_weeks = floor($days / 7);         $no_remaining_days = fmod($days, 7);         //im doing , odd saturday calculations....finally...      $workinghours = $workingdays*9 +  $no_saturdays*7;           return $workinghours;     } 

such expression gives desired result

echo strtotime('midnight', strtotime('2016-04-27 22:11')); // 1461715200 echo strtotime('2016-04-27'); // 1461715200 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -