Documentation

FormatDate

string
CDatabase::FormatDate(
 string date,
 string format = "DD.MM.YYYY HH:MI:SS",
 string new_format = "DD.MM.YYYY HH:MI:SS"
)

The method converts the date from the source format into another. The format allows the following symbols.

Formatter Description
YYYY Year (0001 - 9999)
MM Month (01 - 12)
DD Day (01 - 31)
HH Hours (00 - 24)
MI Minutes (00 - 59)
SS Seconds (00 - 59)

Non-static method.

Parameters

ParameterDescription
date Date to be converted.
format Data current format.
Opcional. By default - "DD.MM.YYYY HH:MI:SS".
new_format Target format to convert into.
Optional. By default - "DD.MM.YYYY HH:MI:SS".

See Also

Examples of use

<?
// specify the date
$date = "31.12.2007";

// set the input date format
$format = "DD.MM.YYYY";

// obtain the format of the current site
$new_format = CSite::GetDateFormat("SHORT"); // YYYY-MM-DD

// perform conversion
$new_date = $DB->FormatDate($date, $format, $new_format);

// get the date in the new format
echo $new_date; // 2007-12-31
?>
<?
// convert date from one site format to another site format

// obtain the '.ru' site format
$format_ru = CSite::GetDateFormat("SHORT", "ru"); // DD.MM.YYYY

// obtain the '.en' site format
$format_en = CSite::GetDateFormat("SHORT", "en"); // YYYY-MM-DD

// perform conversion
$new_date = $DB->FormatDate($date, $format_ru, $format_en);

// get the date in the new format
echo $date; // 2007-12-31
?>


© «Bitrix24», 2001-2024