I am using laravel and carbon package.I have two date. Now I want to get date difference from my given date.
$start_Date='2016-06-02 18:00:13';
$end_Date='2016-06-06 18:00:13';
$start = Carbon::parse($start_Date);
$end = Carbon::parse($end_Date);
$now = Carbon::now();
$length = $start->diffInDays($now);
$lengthFromEnd = $end->diffInDays($now);
if now() == 2016-06-07
then
$length will be 5 days
and
$lengthFromEnd will be -1 days
.
but my code return abnormal result
you can also try this way.
$difference = $start_date->diff($end_date)->days;
For negative result, you need a add parameter, like this:
$absolute = false;
$end->diffInDays($now, $absolute);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With