PHP idate() Function

In this chapter you will learn:

  1. Definition for PHP idate() Function
  2. Syntax for PHP idate() Function
  3. Parameter for PHP idate() Function
  4. Format for PHP idate() Function
  5. Return value for PHP idate() Function
  6. Note for PHP idate() Function
  7. 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

ParameterIs RequiredDescription
formatRequired.Format for the result
timestampOptional.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:

  1. Definition for PHP localtime() Function
  2. Syntax for PHP localtime() Function
  3. Parameter for PHP localtime() Function
  4. Return value for PHP localtime() Function
  5. Example for PHP localtime() Function
Home » PHP Tutorial » PHP Date Functions
PHP checkdate() Function
PHP date() Function
PHP date_add() Function
PHP date_create() Function
PHP date_create_from_format() Function
PHP date_date_set() Function
PHP date_default_timezone_get() Function
PHP date_default_timezone_set() Function
PHP date_diff() Function
PHP date_format() Function
PHP date_get_last_errors() Function
PHP date_interval_format() Function
PHP date_isodate_set() Function
PHP date_modify() Function
PHP date_offset_get() Function
PHP date_parse() Function
PHP date_parse_from_format() Function
PHP date_sub() Function
PHP date_sun_info() Function
PHP date_sunrise() Function
PHP date_sunset() Function
PHP date_time_set() Function
PHP date_timestamp_get() Function
PHP date_timestamp_set() Function
PHP date_timezone_get() Function
PHP date_timezone_set() Function
PHP getdate() Function
PHP gettimeofday() Function
PHP gmdate() Function
PHP gmmktime() Function
PHP gmstrftime() Function
PHP idate() Function
PHP localtime() Function
PHP microtime() Function
PHP mktime() Function
PHP strftime() Function
PHP strptime() Function
PHP strtotime() Function
PHP time() Function
PHP Timezones Constant
PHP timezone_abbreviations_list() Function
PHP timezone_identifiers_list() Function
PHP timezone_location_get() Function
PHP timezone_name_from_abbr() Function
PHP timezone_name_get() Function
PHP timezone_offset_get() Function
PHP timezone_open() Function
PHP timezone_version_get() Function