CodeIgniter Forums

Full Version: Date
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How can I extract day and month from date in Codeigniter 4?
Quick example:

PHP Code:
$timestamp time();

$date date('Y-m-d'$timestamp);
        
$fields explode('-'$date);

echo 
'Year  = '.$fields[0]."<br>";
echo 
'Month = '.$fields[1]."<br>";
echo 
'Day   = '.$fields[2]; 

Or you can use the PHP DateTime object.
If you have a CI4 Time object you can simple use the getters (https://codeigniter4.github.io/CodeIgnit...ml#getters):

$time->day
$time->month