Question: I need to compare two dates and find which date is greater. 

```
 $actual_date = Carbon::createFromFormat('d-m-Y',$night_out->actual_return_date);
 $expected_date =  Carbon::createFromFormat('d-m-Y', $night_out->expected_return_date);

 $days = $expected_date->diffInDays($actual_date);  // gives the days count only

```

Thanks in Advance!

Answer: 
You can use carbon method greaterThan()

```
if($actual_date->greaterThan($expected_date)){
     // logic here
 }

```
Use `gt` function for that:

```
$actual_date = Carbon::createFromFormat('d-m-Y',$night_out->actual_return_date);
$expected_date =  Carbon::createFromFormat('d-m-Y', $night_out->expected_return_date);

if($expected_date->gt($actual_date)){            
    return $expected_date; //Max date
} else {
    return $actual_date;  //Min date
}

```

OR:

You need to find a greater date from two dates using `max` and `array_map` function like:

```
$actual_date = Carbon::createFromFormat('d-m-Y',$night_out->actual_return_date);
$expected_date =  Carbon::createFromFormat('d-m-Y', $night_out->expected_return_date);

// store dates value into an array to find the max date.

$date = array();
$date['actual_date'] = $actual_date;
$date['expected_date'] = $expected_date;

$max = max(array_map('strtotime', $date));

echo date('d-m-Y', $max);

```