Echo out the current date with PHP

echo out current date with php

About this article: Posted in: Learned along the way
By: Blockcoder ( Admin ) / 27.07.2011
Stats: no comments / Views: 938
Tags: ,


Here’s one example function witch uses the date function.

function currentDate()

{
        $day = date("j");
        $month = date("n");
        $year = date("Y");

 echo "Today is ".$day.". day ".$month." ".$year."";
}

When you call the function “currentDate()”, output will be “Today is 28.7.2011″.


I have collected below couple of the most important date arguments:

  • d = day of the month with zeros ( 01 … 31 )
  • j = day of the month without zeros ( 1 … 31 )
  • D = day of the week by letters ( monday … sunday )
  • z = the day of the year ( 0 … 365 )
  • F = month presented by letters ( january … december )
  • m = month number with zeros ( 01 … 12 )
  • n = month number without zeros ( 1 … 12 )
  • Y = year represented by 4 digits ( 2000, 2011, 1977.. )
  • y = year represented by 2 digits ( 89, 02, 76.. )

Another example:

If you want to print out the date like “January 22th, 2011″:

function currentDate()
    {

        $day = date("j");
        $month = date("F");
        $year = date("Y");

        echo $month." ".$day."th, ".$year."";

    } 

There’s also arguments for time and clock and timezone, but those we will go trough next time :)

There are 1 responses on this post

5NRuLJLIStRT4
229404 294653you use a amazing weblog here! do you wish to earn some invite posts on my small weblog? 776572

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *

25,413 Spam Comments Blocked so far by Spam Free Wordpress

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>