Documentation

FormatDate

string
FormatDate(
 string format,
 int timestamp,
int now = time(),
);

The function returns string, formatted in accordance with the specified format based on the time value, defined in the timestamp.

Note: in practice this function acts as wrapper for PHP function date.

Method parameters

Parameter Description Available from version
format Data/time format. The following extensions are supported in addition to the standard symbols:
FormatValueExample
sagoN seconds back2 seconds ago
sdiffN seconds1 second
iagoN minutes ago11 minutes ago
idiffN minutes32 minutes
isagoN minutes M seconds ago4 minutes 12 seconds ago
HagoN hours ago1 hour ago
HdiffN hours3 hours
yesterdayconstantyesterday
today constanttoday
dagoN days ago2 days ago
ddiffN days8 days
mdiffN months6 months
YdiffN years2 years
Fmonth name in genitive caseof January
fmonth name in nominative caseJanuary
Mabbreviated month nameJan
lweekday nameSunday
Dabbreviated weekday nameSun
xtime interval depending on its size.32 seconds ago
49 minutes ago
today, 14:33
yesterday, 12:32
or in site format without seconds.
Xtime interval depending on its size.today
yesterday
or in site format without seconds.
Qtime interval depending on its size.1 day
22 days
3 months
12 years
timestamptimestamp in Unix format
now timestamp in Unix format that is used to calculate intervals. By default - time().

Notes

The 'x' and 'X' formats supports future time specs. If the value of the timestamp parameter is higher than the value of the now parameter (i.e future time is specified), the formats "X" and "x" will return time in the site format without seconds.

Returned value

Formatted string.

See Also

Examples of use

<?
$rsUser = CUser::GetList($by, $order, array(
"ID_EQUAL_EXACT" => $USER->GetID()
));
if($arUser = $rsUser->Fetch())
{
echo "Registered on site: ",FormatDate("Q", MakeTimeStamp($arUser["DATE_REGISTER"])),".";
}
?>


© «Bitrix24», 2001-2024