Wednesday, December 26, 2012
How to display date in PHP
To display date in PHP we use date() function.
<?php echo date("d-m-Y"); ?>
To display time in PHP we can use the same function like this
<?php echo date("h:i:s"); ?> //Outputs hour:minute:seconds as below
Oops don't panic if the time displayed on your screen is different from your clock. To correct it you have to set the default time-zone as below:
date_default_timezone_set('Asia/Kolkata'); //mine is Asia/Kolkata
You may have noticed that in example1 date("d-m-Y") d is small, m is small, Y is capitalized. Is there any relevance in doing so? Yes of-course, there is.
echo date("d-m-y"); //outputs 13-11-11
echo date("d-M-y"); //outputs 13-Nov-11
echo date("D-M-y"); //outputs Sun-Nov-11
To get the complete chart CLICK HERE