Bitrix Site Manager

CDatabase::DateFormatToPHP

string
CDatabase::DateFormatToPHP(
 string date_format
)

The method DateFormatToPHP converts any date and time format allowed by the site settings to the PHP format.

The following rules apply.

Input formatters Output formatters Description
YYYY Y Year (0001 - 9999)
MM m Month (01 - 12)
DD d Day (01 - 31)
HH H Hours (00 - 24)
MI i Minutes (00 - 59)
SS s Seconds (00 - 59)

Parameters

ParameterDescription
date_format Format to be converted.

See Also

Example



<?
// source format
$format = "DD.MM.YYYY HH:MI:SS";

// convert to the PHP format
$php_format = $DB->DateFormatToPHP($format); // d.m.Y H:i:s
?>
<?
// print current date in the format of the current site
// obtain the site format
$site_format = CSite::GetDateFormat("SHORT");

// convert to the PHP format
$php_format = $DB->DateFormatToPHP($site_format);

// print current date in the format of the current site
echo date($php_format, time());
?>
<?
// print yesterday's date in the format of the current site

// obtain the site format
$site_format = CSite::GetDateFormat("SHORT");

// convert to the PHP format
$php_format = $DB->DateFormatToPHP($site_format);

// print yesterday's date in the format of the current site
echo date($php_format, time()-86400);
?>