PROGRAMMING SOLUTIONS

Tuesday 23 June 2009

A simple php function that separates date from time

$d is a date similar to the format yyyy/mm/dd h:m:s , there must be a space between the the date and time part of the given date for the function to work correctly.

If $returnDate is set to true, this function returns the date part
else it returns the time part.

function SeparateDateFromTime($d, $returnDate)
{
$retValue = "";

if ($returnDate==True) { // return date...
$retValue = trim(substr($d, 0, stripos($d, " ")));
}
else { // return time...
$retValue = trim(substr($d, stripos($d, " ")));
}

return $retValue;
}

No comments:

Post a Comment