FreeKB - PHP date format
PHP - date format

Following is an example of how to print the current date in PHP. In this example, the current year will be printed.

   echo date("Y");


If you are fetching data from SQL, use this syntax to format the date in PHP:

   echo $row['date_column']->format('m/d/Y');


You will want to ensure that your php.ini file has the appropriate time zone, like this. If you make a change in php.ini, restart the php service.

date.timezone = America/Chicago


The following markup can be used to determine if date.timezone has been set properly.


$timezone = date_default_timezone_get();

if (strcmp($timezone, ini_get('date.timezone'))){
    echo 'date.timezone in php.ini is not America/Chicago';
else {
    echo 'date.timezone in php.ini is America/Chicago';


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 54d33 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |