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.

<?php
   echo date("Y");
?>

 

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

<?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.

date_default_timezone_set('America/Chicago');

$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 e55ee in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |