|
|
|
Quality business correspondence.
|
|
|
|
Displaying Date & Time with PHP
You use date() with string argument to get the current date or time.
You might also use the function now() to get the current date & time.
For example, these examples will Illustrate use of date and time functions.
| Example | Function | Result |
| <?php echo date("F j, Y"); ?> |
Month name, day & full year |
February 4, 2012 |
| <?php echo date("m/d/y"); ?> |
Mont/day/short year |
02/04/12 |
| <?php echo date("Ymd"); ?> |
Full year, month and day |
20120204 |
| <?php echo date("d"); ?> |
Digit day |
04 |
| <?php echo date("j"); ?> |
Digit day-no leading 0 |
4 |
| <?php echo date("D"); ?> |
Day name |
Sat |
| <?php echo date("m"); ?> |
Digit month |
02 |
| <?php echo date("n"); ?> |
Digit month-no leading 0 |
2 |
| <?php echo date("M"); ?> |
Short month name |
Feb |
| <?php echo date("F"); ?> |
Full month name |
February |
| <?php echo date("t"); ?> |
# of days in current month |
29 |
| <?php echo date("y"); ?> |
Short Year |
12 |
| <?php echo date("Y"); ?> |
Full year |
2012 |
| <?php echo date("w"); ?> |
Day of week 0-Sun 6-Sat |
6 |
| <?php echo date("z"); ?> |
Day of year 0-to-365 |
34 |
| <?php echo date("W"); ?> |
Current week of the year (53w) |
05 |
| <?php echo date("W"); ?> |
Currently week of the year (53w) |
05 |
| <?php echo date("a"); ?> |
am or pm |
am |
| <?php echo date("A"); ?> |
AM or PM |
AM |
| <?php echo date("g"); ?> |
12h format |
6 |
| <?php echo date("G"); ?> |
24h format |
6 |
| <?php echo date("h"); ?> |
12h format with leading 0 |
06 |
| <?php echo date("H"); ?> |
24h with leading 0 |
06 |
| <?php echo date("i"); ?> |
Minutes |
38 |
| <?php echo date("s"); ?> |
Seconds |
27 |
| <?php echo date("T"); ?> |
Timezon |
MST |
Following example utilizes Date() function to illustrate more.
<?php
print "Today's date is: ";
print date("F j, Y");
print " and there is ";
print 365-date("z");
print " days left of the year ";
print date("Y");
?>
Execution Result:
Today's date is: February 4, 2012 and there is 331 days left of the year 2012
|
|
Loops
Database Access
|
|
|