Showing posts with label PHP Date Function Tutorial. Show all posts
Showing posts with label PHP Date Function Tutorial. Show all posts

Sunday, April 29, 2012

PHP Date Function Tutorial


Date Function
To display in numeric format:
1. d, a lower case d, stands for date of the month( 1 to 31).
2. m, a lower case m, stands for the month( 1 to 12).
3. y, a lower case y, stands for the year(in two digits).

To display in text format:
1. D, a capital D, stands for day of the month in tex( Saturday, Sunday, etc. ).
2. M,a capital M, stands for the month in text( 1 to 12).
3. Y, Capital Y, stands for date of the year(in four digits).


To display in numeric format:
Example: 1
        <?php
        echo date("d/m/y");
        ?>
Output
30/04/12

You can change the format like period.
Example: 2
        <?php
        echo date("d.m.y");
        ?>
Output
30.04.12

You can also use minus sign.
Example: 3
        <?php
        echo date("d-m-y");
        ?>}
Output
30-04-12

To display in text format:
Example: 1
        <?php
        echo date("D/M/Y");
        ?>
Output
Mon/Apr/2012

You can change the format like period.
Example: 2
        <?php
        echo date("D.M.Y");
        ?>
Output
Mon.Apr.2012

You can also use minus sign.
Example: 3
        <?php
        echo date("D-M-Y");
        ?>}
Output
Mon-Apr-2012 

To display full date:
Example: 4
        <?php
        echo date("d D M Y");
        ?>}
Output
30 Mon Apr 2012 

The following example will output "Have a nice weekend!" if the current day is Sunday, otherwise it will output "Have a nice day!":
Example: 5
<?php
$d=date("D");
if ($d=="Sun")
  echo "Have a nice weekend!";
else
  echo "Have a nice day!";
?>
Output
Have a nice day!