Home php How to compare the date Carbon

How to compare the date Carbon

Author

Date

Category

I have in the database stored dates in 2020-12-03 06:00:56

Please tell me how to make a condition and return true if this date is less or equal to the current

I use Carbon and Laravel


Answer 1, Authority 100%

very simple
Carbon copes well with comparisons


$ Date1 = Carbon :: Parse ('2020-12-03 06:00:56');
$ DATE2 = Carbon :: Parse ('2020-12-03 06:00:56');
$ Date3 = Carbon :: Parse ('2020-12-03 06:00:56') - & gt; addminute ();
$ Date4 = Carbon :: Parse ('2020-12-03 06:00:56') - & gt; subminute ();
$ DATE1 == $ DATE2; // True.
$ DATE1- & GT; EQ ($ DATE2); // True.
$ DATE1 & GT; $ DATE3; // false;
$ DATE1 & LT; $ DATE3; // True;
$ DATE1 & GT; $ DATE4; // True.
// It is important to note that the warming goes on microseconds! It means that
Carbon :: Now ()! = Carbon :: Now (); // True.
// T.K. When creating carbon instances, microseconds are taken into account that will be different

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions