getdate
(PHP 4, PHP 5)
getdate — Get date/time information
Description
array getdate
([ int
$timestamp
= time()
] )
Returns an associative array containing the date
information of the timestamp
, or the current
local time if no timestamp
is given.
Parameters
Return Values
Returns an associative array of information related to
the timestamp
. Elements from the returned
associative array are as follows:
Key | Description | Example returned values |
---|---|---|
"seconds" | Numeric representation of seconds | 0 to 59 |
"minutes" | Numeric representation of minutes | 0 to 59 |
"hours" | Numeric representation of hours | 0 to 23 |
"mday" | Numeric representation of the day of the month | 1 to 31 |
"wday" | Numeric representation of the day of the week | 0 (for Sunday) through 6 (for Saturday) |
"mon" | Numeric representation of a month | 1 through 12 |
"year" | A full numeric representation of a year, 4 digits | Examples: 1999 or 2003 |
"yday" | Numeric representation of the day of the year | 0 through 365 |
"weekday" | A full textual representation of the day of the week | Sunday through Saturday |
"month" | A full textual representation of a month, such as January or March | January through December |
0 | Seconds since the Unix Epoch, similar to the values returned by time() and used by date(). | System Dependent, typically -2147483648 through 2147483647. |
Examples
Example #1 getdate() example
<?php
$today = getdate();
print_r($today);
?>
The above example will output something similar to:
Array ( [seconds] => 40 [minutes] => 58 [hours] => 21 [mday] => 17 [wday] => 2 [mon] => 6 [year] => 2003 [yday] => 167 [weekday] => Tuesday [month] => June [0] => 1055901520 )
See Also
- date() - Format a local time/date
- idate() - Format a local time/date as integer
- localtime() - Get the local time
- time() - Return current Unix timestamp
- setlocale() - Set locale information
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с датой и временем
- Дата и Время
- checkdate
- date_add
- date_create_from_format
- date_create_immutable_from_format
- date_create_immutable
- date_create
- date_date_set
- date_default_timezone_get
- date_default_timezone_set
- date_diff
- date_format
- date_get_last_errors
- date_interval_create_from_date_string
- date_interval_format
- date_isodate_set
- date_modify
- date_offset_get
- date_parse_from_format
- date_parse
- date_sub
- date_sun_info
- date_sunrise
- date_sunset
- date_time_set
- date_timestamp_get
- date_timestamp_set
- date_timezone_get
- date_timezone_set
- date
- getdate
- gettimeofday
- gmdate
- gmmktime
- gmstrftime
- idate
- localtime
- microtime
- mktime
- strftime
- strptime
- strtotime
- time
- timezone_abbreviations_list
- timezone_identifiers_list
- timezone_location_get
- timezone_name_from_abbr
- timezone_name_get
- timezone_offset_get
- timezone_open
- timezone_transitions_get
- timezone_version_get
Коментарии
function getFormattedDate(){
$dateArray = getdate();
$day = sprintf("%02d", $dateArray['mday']); // Current day (for example 10)
$month = sprintf("%02d", $dateArray['mon']); // Current month (for example 6)
$year = $dateArray['year']; // Current year (for example 2023)
$formattedDate = $day . "." . $month . "." . $year; // DD.MM.YYYY
return $formattedDate;
}
echo getFormattedDate(); // It should turn out 10.06.2023