I have a problem outputting the date which is created within my `PHP` file.

I've been following a tutorial on how to make a really Basic-CMS Platform to help me understand some of the basics for `databases` and `PHP`, everything has been going well up until I was trying to output the date of when the page was created.

This is the error I get

```
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings. 
You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of
those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.' in 
C:\MAMP\htdocs\basic-cms\page.php:22 Stack trace: #0 C:\MAMP\htdocs\basic-cms\page.php(22): DateTime->__construct('2016-02-17 10:3...') #1 {main} thrown in C:\MAMP\htdocs\basic-cms\page.php on line 22

```

Now when I remove line 22 inside my `page.php` it outputs the full date that is inside the database i.e `2016-02-17 10:38:05` but I'm trying to format it to show the date like `jS M, Y (17th Feb 2016)`.

This is the code inside my `page.php` file

```
if ( $page ) {
    $page['created'] = new DateTime( $page['created'] );

    if ( $page['updated'] ) {
        $page['updated'] = new DateTime( $page['created'] );
    }
}

```

Then inside my `show.php` where I'm displaying this I have this code to format the date.

```
Created on <?php echo $page['created']->format('jS M, Y'); ?>

```

Now removing this from my `show.php` doesn't do anything as that's not where the error is contained - but I thought I'd show you guys what I am trying to achieve.

Like I said this is a very Basic-CMS site that I am creating by following a [tutorial on YouTube](https://www.youtube.com/watch?v=Hvb0oeMbH0U&list=PLfdtiltiRHWF0O8kS5D_3-nTzsFiPMOfM&index=4) and I have copied his code exactly and he got no error so I'm sure it has to be a typo I just can't find.
['https://Stackoverflow.com/questions/35455315', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5006451/']
This is because no timezone has set in php configuration.

Add the following line of code to top of your php.ini file

```
date.timezone = "US/Central"

```

And restart web server

**OR**

you can set it via php script also by using following function:

```
date_default_timezone_set('America/Los_Angeles');

```

Dont forget to reload/restart apache server
**If you're using a database to hold the page details when its created:**

You can actually just add a DateTime Column in your database and then when the page is created and you Insert whatever you need to add, make the Column a default TimeStamp and it should automatically add the time and date the page was created for you.

To then get the TimeStamp out of the database (MySQLi version):

```
$db = mysqli_connect('host', 'user', 'pass', 'dbname');
$result = $db->query("SELECT * FROM tbl_name");
// add an error check here
while($row = mysqli_fetch_array($result)){
   if($row['columnPageID'] == 'the page ID you are on'){
       $createdOn = $row['columnName'];
   }
}
$db->close();

```

This code will **not** work, its so you get an understanding.