Simple web design, web development, information technology, & technical communication

Articles and resources for web developers and the average person. Topics include web development, web design, technical writing and communication, and all aspects of information technology.

How do I print the date using PHP?

Originally published on Monday, September 5th, 2005

PHP offers an excellent built-in function for printing dates. Here are some of the most common date formats and how you can print them using PHP.

Remember, each PHP block of code should start with <?php or <? and end with ?>. The “echo” statement actually outputs the data to the screen. This is by no means a complete reference guide. For a complete list of all the date function output parameters, see the references at the bottom of the article.

Common PHP date formatting


<?php

// Prints the year, i.e. 2005

echo date("Y");

// Prints the day, i.e. Monday

echo date ("l") ;

// Prints the month, i.e. March

echo date("F");

// Prints the day of the month without leading zeros, i.e. 12

echo date("j");

?>

Putting it all together: PHP dates you might use


<?

// Prints something like January 24, 2005

echo date("F j, Y");

// Outputs something like Monday, February 17th, 2005

echo date("l, F jS, Y");

// Outputs date in format of 10/24/2005 for October 24th 2005

echo date("m/d/Y");

?>

Further reading on outputting dates in PHP

Add a Comment

You must be logged in to post a comment.

Categories

Stay Updated