【发布时间】:2015-09-25 05:45:45
【问题描述】:
我需要计算两个日期之间的天数。 我输入的所需日期,在给定日期之前从数据库中获取记录。 如果数据库的“开始日期”为 2015 年 1 月 1 日,“结束日期”为 2015 年 2 月 5 日。 对于 1 月份,它应该返回 30 和 2 月 5 天。
我的桌子:
id Name Type Project Place Start Date End Date Details
1 Sai Local Site Bangalore 2015-09-03 11:32:47 2015-09-05 11:32:47 test
2 Ram Local IGCAR Chennai 2015-04-01 15:15:36 2015-04-09 15:15:36 Installation
3 Mani Local IGCAR Chennai 2015-04-16 15:16:18 2015-05-21 15:16:18 Training
我的编码
///////////Employee Outstation(Travel) details/////////////
$employeeTravel = new EmployeeTravelRecord();
//date_start = '2015-04-01' ;
//date_end = '2015-04-30';
$TravelEntryList = $employeeTravel->Find("(travel_date between ? and ? or return_date between ? and ? )",array($req['date_start'], $req['date_end'],$req['date_start'], $req['date_end']));
foreach($TravelEntryList as $Travelentry){
$amount = (strtotime($Travelentry->return_date) - strtotime($Travelentry->travel_date));
}
对于第二条记录,它返回正确的值,但对于第三条记录,它计算包括五月。但我只想要 30 天的 4 月。
【问题讨论】:
-
这是昨天的daysAgo visual,您可以在等待代码删除时查看