我需要通过从datetime.datetime()中减去currentDate和日期来计算天数。 currentDate = datetime.date(2016,12,1) randomDate = datetime.datetime(2016,12,1,4,25)
numDays =(currentDate-randomDate)#but我不能这样做因为类型不同
答案 0 :(得分:0)
您可以使用此方法查找两天的差异
$current_date = time(); // or your date as well
$random_date = strtotime("2010-01-01");
$datediff = $current_date - $random_date;
echo floor($datediff / (60 * 60 * 24));
从PHP Version > 5
以下添加新日期/时间功能以获得差异
$datetime1 = new DateTime("2010-06-20");
$datetime2 = new DateTime("2011-06-22");
$difference = $datetime1->diff($datetime2);
echo 'Difference: '.$difference->y.' years, '
.$difference->m.' months, '
.$difference->d.' days';
结果将如下:
Difference: 1 years, 0 months, 2 days