Documentation

MakeTimeStamp

int
MakeTimeStamp(
 string datetime,
 string format = FORMAT_DATETIME
);

This function converts time from the string to Unix format.

Function parameters

ParameterDescription
datetime Original time.
format_type Time format specified in the datetime parameter. The following designations are available within format:
  • YYYY - year
  • MM - month
  • DD - day
  • HH - hours
  • MI - minutes
  • SS - seconds
Optinoal, by default [link=6658092#format_datetime] FORMAT_DATETIME[/link] constant is used that stores current time format of site (or language for administrative section).

See Also

Examples of use

<?
// set date
$date = "07.04.2005 11:32:00";

// convert to Unix-timestamp
if ($stmp = MakeTimeStamp($date, "DD.MM.YYYY HH:MI:SS"))
{
	// display the same date obtained 
	// fromUnix-timestamp
	echo date ("d.m.Y H:i:s", $stmp);
}
else // if false returned...
{
	// display error msg
	echo "Date is incorrect!";
}
?>
<?
// print the date of information block activity
// in arbitrary format

// connect the information block module 
if (CModule::IncludeModule("iblock"))
{
    // select an arbitrary element of information block  
    $rsElement = CIBlockElement::GetByID(32675);
    $arElement = $rsElement->Fetch();

    // obtain the activity date of selected element
    // date selected in the current site format
    $date_active = $arElement["ACTIVE_FROM"]; // 28.01.2005
    
    // get the current site time format
    $site_format = CSite::GetDateFormat(); // DD.MM.YYYY HH:MI:SS

    // convert to Unix format
    if ($stmp = MakeTimeStamp($date_active, $site_format))
    {
        // display the element activity date in arbitrary format 
        // using the PHP date function
        echo date "d F Y", $stmp); // 28 January 2005
    }
    else // if conversion fails
    {
        // display error msg
        ShowError("Date of element 32675 activity is incorrect!");
    }
}
?>


© «Bitrix24», 2001-2024
Up