Showing the Current Date on your site with PHP
February 6th, 2007
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
A lot of websites show the current date somewhere on the site whether it be in the header or sidebar area. Over on WebReference.com there is a long article about using Javascript to do this.
Granted, if you are trying to learn Javascript this is probably a good article to read. Yet, if you simply want to display the current date on your website PHP is the way to go.
Their are a couple of strengths of using PHP to display the current date. First, you don’t have to worry whether your visitors have Javascript turned on or off. Second, you can accomplish in one line of code what takes a good bit of Javascript to do.
Below are quite a few different ways to display the current date using PHP:
Example: February 6, 2007
< ?php echo date('F j, Y'); ?>
Example: Feb. 6th
< ?php echo date('M. jS'); ?>
Example: 06-02-2007 (d-m-y)
< ?php echo date('d-m-y'); ?>
There are many ways to use PHP to display the current date, and they are all simple as pie. Take a look at the PHP website to see all of the different ways that you can display the date using PHP.
March 12th, 2007 at 8:47 am
“Yet, if you simply want to display the current date on your website PHP is the way to go”
Granted your server environment has PHP installed *and* you want to use it. If not, Ruby, Python, JSP, ASP, etc. might be the way to go…