(int)$wakeUpTime[0]|| ((int)$sleepTime[0]==(int)$wakeUpTime[0]&&(int)$sleepTime[1]>=(int)$wakeUpTime[0])){ $sleepTime=date_time_set($yesterday,(int)$sleepTime[0],(int)$sleepTime[1]); $wakeUpTime=date_time_set($today,(int)$wakeUpTime[0],(int)$wakeUpTime[1]); $diff=date_diff($sleepTime,$wakeUpTime); $oneSleepInterval=$diff->format('%H:%I'); $oneSleepInterval=explode(":",trim($oneSleepInterval)); $allSleepTimeHour +=(int)$oneSleepInterval[0]; $allSleepTimeMin +=(int)$oneSleepInterval[1]; // $allSleepTime+=$oneSleepInterval; }else{ //日付またがず寝ているとき // どうも、日付をまたいでいないとdate_diff使えないみたい $sleepTime=date_time_set($yesterday,(int)$sleepTime[0],(int)$sleepTime[1]); $wakeUpTime=date_time_set($today,(int)$wakeUpTime[0],(int)$wakeUpTime[1]); $diff=date_diff($sleepTime,$wakeUpTime); $oneSleepInterval=$diff->format('%H:%I'); $oneSleepInterval=explode(":",trim($oneSleepInterval)); $allSleepTimeHour +=(int)$oneSleepInterval[0]; $allSleepTimeMin +=(int)$oneSleepInterval[1]; } } $ans=($allSleepTimeHour*60)+$allSleepTimeMin; echo $ans;