Get current datetime in cakephp


Get current datetime in cakephp : If you are working with cake php you often need to work with date time function to get current date time in cakephp. Here we are going to explain the date time in cakephp.

Get current datetime in cakephp Syntax

You get current date time in cakephp as below

Get current datetime in cakephp Syntax

<?php
namespace App\Controller;
use Cake\I18n\Time;
class UsersController extends AppController
{                     
public function currentTimeInCake(){                                                                                                            return   Time::createFromFormat(
    'Y-m-d H:i:s',
    Time::now(),
    'America/New_York'
);
}
}

or 
$currDateTime = date("Y-m-d H:i:s");

?>

The above function will return the current date time in cakephp.

Note 1 : Please note that I18n extenssion is recommended for cake 3.0.
Note 2 : Helper for datetime functions is TimeHelper which is used to work with date time in cakephp.

Advertisements

Add Comment

📖 Read More