Reputation: 2073
I am using date_diff to get the days in between two days as followed:
//DATE
$current_date = date_create(date("m.d.y"));
$move_date = date_create($move['moving_day']);
/* Difference between Moving and Current Date */
$difference1 = date_diff($current_date, $move_date);
$date_difference = $difference1->format('%a');
The date is 2016-05-30 and the current is 2016-05-22 but it shows me 7, but it should give me 8.
print_r give me that
DateTime Object
(
[date] => 2016-05-22 05:22:16.000000
[timezone_type] => 3
[timezone] => UTC
)
DateTime Object
(
[date] => 2016-05-30 00:00:00.000000
[timezone_type] => 3
[timezone] => UTC
)
What am I doing wrong?
Upvotes: 0
Views: 83
Reputation: 26153
if you want to don't depend on time of days, shift time to 00:00:00 in such way:
$current_date = date_create(date("m.d.y"))->modify('midnight');
$move_date = date_create($move['moving_day'])->modify('midnight');
Upvotes: 1
Reputation: 1531
The result is correct, if you change current time to 2016-05-30 06:00:00 it will return 8 days
Upvotes: 0