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.
<?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");
?>
<?
// 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");
?>
You must be logged in to post a comment.