w3resource

PHP: idate() function

Description

The idate() function is used to get a local time/date format as an integer.

Version:

(PHP 4 and above)

Syntax:

idate(format, timestamp) 

Parameters:

Name Description Required /
Optional
Type
format 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 when DST is activated otherwise 0
L - returns 1 for leap year otherwise 0
m - Month number
s - Seconds
t - Days in current month
U - Seconds since the Unix Epoch - January 1 1970 00:00:00 UTC
w - Day of the week (0 on Sunday)
W - ISO-8601 numeric week of year, weeks starting on Monday
y - Year
Y - Year in 4 digits
z - Day of the year
Z - Timezone offset in seconds

Optional String
timestamp An integer indicates the unixtimestamp. If a timestamp is not supplied, it gives the current local time. Optional integer

Return value:

An integer value.

Value Type: Integer.

Example:

<?php
echo idate('d');
?> 

Sample Output:

19

View the example in the browser

See also

PHP Function Reference

Previous: gmstrftime
Next: localtime



PHP: Tips of the Day

Getting all defined constants

To get all defined constants including those created by PHP use the get_defined_constants function:

Example:

<?php
$constants = get_defined_constants();
var_dump($constants); // pretty large list

Output:

array(2250) {
  ["E_ERROR"]=>
  int(1)
  ["E_RECOVERABLE_ERROR"]=>
  int(4096)
  ["E_WARNING"]=>
  .....
  .....
  resource(1) of type (stream)
  ["STDOUT"]=>
  resource(2) of type (stream)
  ["STDERR"]=>
  resource(3) of type (stream)
}

To get only those constants that were defined by your app call the function at the beginning and at the end of your script (normally after the bootstrap process):

<?php
$constants = get_defined_constants();
define("HELLO", "hello");
define("WORLD", "world");
$new_constants = get_defined_constants();
$myconstants = array_diff_assoc($new_constants, $constants);
var_export($myconstants);

Output:

array (
  'HELLO' => 'hello',
  'WORLD' => 'world',
)

It's sometimes useful for debugging