Printing the Date in PHP

To print the date in the following format:

2008-06-27 use:

<?php echo date("Y-m-d"); ?>

This is useful for automatically updating the date in the copyright section of a web page:

Copyright © <?php echo date("Y"); ?> Painted Pixels.

Once this is in place on a web page, the year will be adjusted saving yourself the job of having to do it manually.

For other date formats see the PHP Manual.

Comments are closed.