Documentation

DateFormatToPHP

string
CDatabase::DateFormatToPHP(
 string format
)

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

Conversion rules:

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
format Format to be converted. Before version 12.0.7 it was called date_format

Se Also

Examples of use

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

// convert to the PHP format
$php_format = $DB->DateFormatToPHP($format); // d.m.Y H:i:s
?>
<?
// show current date in the current site format 

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

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

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

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

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

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


© «Bitrix24», 2001-2024
Up