PHP Tutorial - PHP idate() Function






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/*  w  w w  .  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.