Search code examples
phplaravelphp-carbon

Calculate the remaining days on view Laravel, negative days if date has passed


These are the values on my database, I just need to get the remaining days of each today:

SQL table

{{ \Carbon\Carbon::now()->diffInDays($patient->date_end) }}

Solution

  • the problem solved but , im confused with the may 7 , which is the 3rd row should give me a negative value

    If you want to get the negative values, you would need to pass false as the second parameter of the diffInDays function.

    Carbon\Carbon::now()->diffInDays($patient->date_end, false)
    

    The second parameter sets whether you want the absolute difference or not. Default is true, which returns absolute difference.