PHP idate() Function
In this chapter you will learn:
- Definition for PHP idate() Function
- Syntax for PHP idate() Function
- Parameter for PHP idate() Function
- Format for PHP idate() Function
- Return value for PHP idate() Function
- Note for PHP idate() Function
- Example
Definition
The idate() function formats a local time and/or date as integer.
Syntax
PHP idate() Function has the following syntax.
idate(format,timestamp);
Parameter
Parameter | Is Required | Description |
---|---|---|
format | Required. | Format for the result |
timestamp | Optional. | A Unix timestamp that represents the date and/or time to be formatted. Default is the current local time (time()) |
Format
Format letter
- B - Swatch Beat/Internet Time
- d - Day of the month
- h - Hour (12 hour format)
- H - Hour (24 hour format)
- i - Minutes
- I - returns 1 if DST (daylight saving time) is activated, 0 otherwise
- L - returns 1 for leap year, 0 otherwise
- m - Month number
- s - Seconds
- t - Days in current month
- U - Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
- w - Day of the week (Sunday=0)
- W - ISO-8601 week number of year (week starts on Monday)
- y - Year (1 or 2 digits)
- Y - Year (4 digits)
- z - Day of the year
- Z - Timezone offset in seconds
Return
PHP idate() Function returns an integer formatted according the specified format using the given timestamp.
Note
The idate() function accepts just one character in the format parameter!
Example
Format a local time/date as integer. Test all the different formats:
<?php//from ja va 2 s . c o m
echo idate("B") . "\n";
echo idate("d") . "\n";
echo idate("h") . "\n";
echo idate("H") . "\n";
echo idate("i") . "\n";
echo idate("I") . "\n";
echo idate("L") . "\n";
echo idate("m") . "\n";
echo idate("s") . "\n";
echo idate("t") . "\n";
echo idate("U") . "\n";
echo idate("w") . "\n";
echo idate("W") . "\n";
echo idate("y") . "\n";
echo idate("Y") . "\n";
echo idate("z") . "\n";
echo idate("Z") . "\n";
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP localtime() Function
- Syntax for PHP localtime() Function
- Parameter for PHP localtime() Function
- Return value for PHP localtime() Function
- Example for PHP localtime() Function
Home » PHP Tutorial » PHP Date Functions