PHP – Get current date and time

In this post we will be creating a PHP script that will return the current date and time and print this to a webpage. To do this we will be using the ‘date()’ function which formats a Unix timestamp.

See the snippet of code which will print the current date and time to a webpage. This by default will go by your server time.

   $date = date('Y-m-d H:i:s');

An example of what the above would return can be seen as.

Leave a Reply