date


time apg

RETURNS the formated local time or date.


This function is NOT COMPATIBLE with LOCALE



<?php

str date 
str $format int|null $timestamp null )

where,

$format The parameter to format the outputted date

$timestamp 
The timestamp to be considered

?>

 $format 

RECOGNIZED CHARACTERS
format character Description Example returned values
Day
d Day of the month, 2 digits with leading zeros 01 to 31
D A textual representation of a day, three letters Mon through Sun
j Day of the month without leading zeros 1 to 31
l A full textual representation of the day of the week Sunday through Saturday
N ISO-8601 numeric representation of the day of the week
Since PHP 5.1.0
1 (for Monday) through 7 (for Sunday)
S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th.
Works well with j
w Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)
z The day of the year (starting from 0) 0 through 365
Week
W ISO-8601 week number of year, weeks starting on Monday Example:
42 (the 42nd week in the year)
Month
F A full textual representation of a month, such as January or March January through December
m Numeric representation of a month, with leading zeros 01 through 12
M A short textual representation of a month, three letters Jan through Dec
n Numeric representation of a month, without leading zeros 1 through 12
t Number of days in the given month 28 through 31
Year
L Whether it's a leap year 1 if it is a leap year, 0 otherwise.
o ISO-8601 week-numbering year.
This has the same value as Y,
except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.
Since PHP 5.1.0
Examples:
1999 or 2018
Y A full numeric representation of a year, 4 digits Examples:
1999 or 2018
y A two digit representation of a year Examples:
99 or 18
Time
a Lowercase Ante meridiem and Post meridiem am or pm
A Uppercase Ante meridiem and Post meridiem AM or PM
B Swatch Internet time 000 through 999
g 12-hour format of an hour without leading zeros 1 through 12
G 24-hour format of an hour without leading zeros 0 through 23
h 12-hour format of an hour with leading zeros 01 through 12
H 24-hour format of an hour with leading zeros 00 through 23
i Minutes with leading zeros 00 to 59
s Seconds, with leading zeros 00 through 59
u Microseconds - Since PHP 5.2.2.
Note that date will always generate 000000
since it takes an integer parameter,
whereas DateTime::format does
support microseconds if DateTime created with microseconds.
Example: 654321
v Milliseconds - Since PHP 7.0.0.
Same note applies as for u.
Example: 654
Timezone
e Timezone identifier
Since PHP 5.1.0
Examples: UTC, GMT, Atlantic/Azores
I (capital i) Whether or not the date is in Daylight Saving Time 1 if DST, 0 if not DST.
O Difference to Greenwich time (GMT) in hours Example: +0200
P Difference to Greenwich time (GMT)
with colon between hours and minutes.
Since PHP 5.1.3
Example: +02:00
T Timezone abbreviation Examples: EST, MDT ...
Z Timezone offset in seconds.
The offset for timezones west of UTC
is always negative,
and for those east of UTC is always positive.
-43200 through 50400
Full Date/Time
c ISO 8601 date (added in PHP 5) 2004-02-12T15:19:21+00:00
r RFC 2822 formatted date Example:
Thu, 21 Dec 2000 16:01:07 +0200
U Seconds since the Unix Epoch:
January 1 1970 00:00:00 GMT
See also the function time
ed48


 PREDEFINED DATE CONSTANTS 

FORMAT DATES
Usual Interface DateTimeInterface
STRING
DESCRIPTION
DATE_ATOM DateTimeInterface::ATOM
Y-m-d\TH:i:sP
Atom:
2018-08-15T15:52:01+00:00
DATE_COOKIE DateTimeInterface::COOKIE
l, d-M-Y H:i:s T
HTTP Cookies:
Monday, 15-Aug-2018 15:52:01 UTC
* DATE_ISO8601 DateTimeInterface::ISO8601
Y-m-d\TH:i:sO
ISO-8601:
2018-08-15T15:52:01+0000
DATE_RFC822 DateTimeInterface::RFC822
D, d M y H:i:s O
RFC 822:
Mon, 15 Aug 18 15:52:01 +0000
DATE_RFC850 DateTimeInterface::RFC850
l, d-M-y H:i:s T
RFC 850:
Monday, 15-Aug-18 15:52:01 UTC
DATE_RFC1036 DateTimeInterface::RFC1036
D, d M y H:i:s O
RFC 1036:
Mon, 15 Aug 18 15:52:01 +0000
DATE_RFC1123 DateTimeInterface::RFC1123
D, d M Y H:i:s O
RFC 1123:
Mon, 15 Aug 2018 15:52:01 +0000
DATE_RFC2822 DateTimeInterface::RFC2822
D, d M Y H:i:s O
RFC 2822:
Mon, 15 Aug 2018 15:52:01 +0000
DATE_RFC7231 DateTimeInterface::RFC7231
D, d M Y H:i:s \G\M\T
RFC 7231:
Mon, 15 Aug 2018 15:52:01 GMT
DATE_RFC3339 DateTimeInterface::RFC3339
Y-m-d\TH:i:sP
Same as DATE_ATOM
Since PHP 5.1.3
DATE_RFC3339_EXTENDED DateTimeInterface::RFC3339_EXTENDED
Y-m-d\TH:i:s.vP
RFC3339_EXTENDED format
Since PHP 7.0.0
2018-08-15T15:52:01.000+00:00
DATE_RSS DateTimeInterface::RSS
D, d M Y H:i:s O
RSS:
Mon, 15 Aug 2018 15:52:01 +0000
DATE_W3C DateTimeInterface::W3C
Y-m-d\TH:i:sP
World Wide Web Consortium:
2018-08-15T15:52:01+00:00
ed48

* This format is not compatible with ISO-8601, but is left this way for backward compatibility reasons.

Use DATE_ATOM or DateTime::ATOM for compatibility with ISO-8601 instead.


 $timestamp 


The timestamp to be considered.





See also:

 gmdate  and  date_create_from_format  for related formats.

Since PHP 8.0.0 $timestamp is nullable.



  1 EXERCISE   

<?php


$datef01a 
= [ 'DATE_ATOM' => DATE_ATOM
               
'DATE_COOKIE' => DATE_COOKIE
               
'DATE_ISO8601' => DATE_ISO8601
               
'DATE_RFC822' => DATE_RFC822,    
               
'DATE_RFC850' => DATE_RFC850,              
               
'DATE_RFC1036' => DATE_RFC1036
               
'DATE_RFC1123' => DATE_RFC1123,
               
'DATE_RFC2822' => DATE_RFC2822
               
'DATE_RFC7231' => DATE_RFC7231,
               
'DATE_RFC3339' => DATE_RFC3339
               
'DATE_RFC3339_EXTENDED' => 
                               
DATE_RFC3339_EXTENDED
               
'DATE_RSS' => DATE_RSS
               
'DATE_W3C' => DATE_W3C ];

foreach(
$datef01a as $k01a => $v01a)
{
    echo 
$k01a '<br>' $v01a '<br>';
    echo 
date($v01a) . '<br><br>';
}

?>

  2 EXERCISE   

<?php

$str_tz 
'Asia/Tokyo';

$tzok date_default_timezone_set($str_tz);

// If the timezone is not assigned, UTC will be considered

$datef_01 date("l F d Y h:i:s A");

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

$ts_now time(); 
// CURRENT TIMESTAMP

$datef_02 =  date("l F d Y H:i:s"$ts_now);

echo 
'date("l F d Y h:i A")<br><br>' $datef_01;

echo 
'<br><br><br>date("l F d Y H:i:s", time())<br><br>' $datef_02 '<br>';

?> 

  3 EXERCISE   

<?php

$str_tz 
'UTC';

$tzok date_default_timezone_set($str_tz);

$ts_zero 0
// VALUE OF TIMESTAMP EQUAL TO ZERO

$datef_03 =  date("l F d Y H:i:s"$ts_zero);

echo 
'<br><br><br>date("l F d Y H:i:s", time())<br><br>' $datef_03 '<br>';

?> 

  4 EXERCISE   

<?php 

$str_tz 
'UTC'

$tzok date_default_timezone_set($str_tz); 

$ts_ant = -112345678
// VALUE OF TIMESTAMP LESS THAN ZERO

$datef_04 =  date("l F d Y H:i:s"$ts_ant); 

echo 
'<br><br><br>date("l F d Y H:i:s", time())<br><br>' $datef_04 '<br>';

?> 

  5 EXERCISE   

<?php 

$str_tz 
'Asia/Tokyo'

$tzok date_default_timezone_set($str_tz); 

// If the timezone is not assigned, UTC will be considered 

$datef_05 date("D, d M Y H:i:s \G\M\T"); 

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

$ts_now time();
// CURRENT TIMESTAMP 

$datef_06 =  date("l F d Y H:i:s"$ts_now); 

echo 
'date("l F d Y h:i A")<br><br>' $datef_05

echo 
'<br><br><br>date("l F d Y H:i:s", time())<br><br>' $datef_06 '<br>'

?>  

  6 EXERCISE   

<?php 

$str_tz 
'UTC'

$tzok date_default_timezone_set($str_tz); 

// If the timezone is not assigned, UTC will be considered 

$datef_06 date(DATE_COOKIE); 

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

$ts_now time(); 
// CURRENT TIMESTAMP 

$datef_07 =  date(DATE_COOKIE$ts_now); 

echo 
'date(DATE_COOKIE)<br><br>' $datef_06

echo 
'<br><br><br>date(DATE_COOKIE, time())<br><br>' $datef_07 '<br>'

?>  

  7 EXERCISE   

<?php 

$str_tz 
'America/Los_Angeles'

$tzok date_default_timezone_set($str_tz); 

$datef07a = [ "DATE_TOM" => DateTimeInterface::ATOM
               
"DATE_COOKIE" => DateTimeInterface::COOKIE
               
"DATE_ISO8601" => DateTimeInterface::ISO8601
               
"DATE_RFC822" => DateTimeInterface::RFC822,    
               
"DATE_RFC850" => DateTimeInterface::RFC850,              
               
"DATE_RFC1036" => DateTimeInterface::RFC1036
               
"DATE_RFC1123" => DateTimeInterface::RFC1123,
               
"DATE_RFC2822" => DateTimeInterface::RFC2822
               
"DATE_RFC7231" => DateTimeInterface::RFC7231,
               
"DATE_RFC3339" => DateTimeInterface::RFC3339
               
"DATE_RFC3339_EXTENDED" => 
                                
DateTimeInterface::RFC3339_EXTENDED
               
"DATE_RSS" => DateTimeInterface::RSS
               
"DATE_W3C" => DateTimeInterface::W3C ]; 
               
               foreach(
$datef07a as $k07 => $v07)
               {   
                   echo 
$k07 '<br>' $v07 '<br>';
                   echo 
date($v07) . '<br><br>';
               }
               

?>