Compare Dates and Times in CodeIgniter 4 Tutorial
If we have two or more than two dates and times. In case if we want some differences — After, Before, same, equal how can we see. In codeigniter 4 we have few functions of Time class, by the help of which we can easily do these things.
In this article we will discuss the concept of compare dates and times in codeigniter 4 tutorial.
In addition we have few more articles, please check these also –
- Find Date Differences in CodeIgniter 4 Tutorial
- CodeIgniter 4 Getter And Setter Time Class Methods
- Concept of Date And Time in CodeIgniter 4 Tutorial
Here is the command to install via composer –
$ composer create-project codeigniter4/appstarter codeigniter-4
Assuming you have successfully installed application into your local system.
What is Time Class & Create Instance
This class is the Time class and lives in the CodeIgniter\I18n namespace. Inside this article we will see the concept of Date and Time in CodeIgniter 4. Also we will see available methods of Time Class in great detail.
To use Time Class in CodeIgniter 4 application, we need to do these things -
- Import CodeIgniter\I18n\Time
- Create Instance of Time()
Here, we have few examples to load and use Time() class.
use CodeIgniter\I18n\Time; $myTime = new Time('+3 week');
Compare Functions in CodeIgniter 4
Here, we have few functions of Time class which we can use to compare date and time instance values.
- equals()
- sameAs()
- isBefore()
- isAfter()