idate 


php apg

FORMATS a date fragment as integer, from a given TIMESTAMP.



<?php

int
|false idate ( str $format , int|null $timestamp = null )


where,

$format = Just one character to format the date
               
( SEE the below TABLE )

$timestamp = The UNIX timestamp

?>

 $format 

CHARACTER VALUES MEANING
B SWT Swatch Beat/Internet Time
d 1, 2, 3, ...., 31 Day of the month
h 01, 02, 03, ..., 12 hour 12h format
H 00, 01, 02, ..., 23 hour 24h format
i 00, 01, 02, ..., 59 minutes
I 0 Out of DST
1 DST
L 0 Normal year
L 1 Leap year
m 1, 2, ..., 12 month number
s 00, 01, ..., 59 seconds
t 28, 29, 30 and 31 number of days in the month
U 1, 1970 00:00:00 GMT seconds since
w 0 -> Sunday,
1 -> Monday,
....,
6 -> Saturday
number of the day of the week
W ISO-8601 Number of the year according to
y 2 dígits Year
Y 4 dígits Year
z 0, 1, ..., 365 Number of day in year
Z -43200 a 43200
(15 degrees = 1 hour)
Timezone Offset in seconds
ed48


 $timestamp 


The related UNIX timestamp.





This function accepts just one character to $format.

The $timestamp has the same value of time.

Since PHP 8.0.0 $timestamp is nullable.



  1 EXERCISE   

<?php

$lang 
= 'en';

/* - - - - - - - - - - - - - - - - - - - - - - - - -
   If $int_timestamp, is not provided, 
   the current value of time() will be considered
   - - - - - - - - - - - - - - - - - - - - - - - - - */

$idate_now = idate('B');
$en = 'Internet Time (now) = ';

echo $
$lang . $idate_now . ' beat';

?> 

  2 EXERCISE   

<?php

$lang 
= 'en';

/* - - - - - - - - - - - - - - - - - - - - - - - - -
   If $int_timestamp, is not provided, 
   the current value of time() will be considered
   - - - - - - - - - - - - - - - - - - - - - - - - - */

$idate_now = idate('Y');
$pt = 'Este Ano = ';
$en = 'This Year = ';
echo $
$lang . $idate_now;


?> 

  3 EXERCISE   

<?php

$lang 
= 'en';

$idate_day = idate('d');
$idate_month = idate('m');
$idate_year = idate('Y');

$pt = 'Hoje = ';
$en = 'Today = ';
echo $
$lang . $idate_year . '/' . $idate_day . '/' . $idate_month;

?> 

  4 EXERCISE   

<?php

// run this exercise several times

$arrid04 = [ "B" => "Swatch Beat-Internet Time", 
                   
"d" => "Day of the month", 
                   
"h" => "Hour (12 hour format)", 
                   
"H" => "Hour (24 hour format)", 
                   
"i" => "Minutes", 
                   
"s" => "Seconds", 
                   
"I" => "DST?", 
                   
"L" => "leap year?", 
                   
"m" => "Month number", 
                   
"t" => "Days in current month", 
                   
"U" => "TIMESTAMP", 
                   
"w" => "Day of the week", 
                   
"W" => "ISO-8601 week number of year", 
                   
"y" => "Year (1 or 2 digits)", 
                   
"Y" => "Year (4 digits)", 
                   
"z" => "Day of the year", 
                   
"Z" => "Timezone offset in seconds" ];

foreach(
$arrid04 as $vl04 => $v04)
{
    echo 
'&nbsp;&nbsp;[' . $vl04 . ']&nbsp;&nbsp;' . 
              
idate($vl04) . '&nbsp;&nbsp;=>&nbsp;' . 
              
$v04 . '<br>';
}

?>