Skip to content

Instantly share code, notes, and snippets.

@phpmaps
Created November 23, 2013 06:03
Show Gist options
  • Save phpmaps/7611348 to your computer and use it in GitHub Desktop.
Save phpmaps/7611348 to your computer and use it in GitHub Desktop.
PHP helpers
public function makeDirectory($dir, $mode = 0666) //Not implemented.
{
if (is_dir($dir) || @mkdir($dir,$mode)) return true;
if (!$this->makeDirectory(dirname($dir),$mode)) return false;
return @mkdir($dir,$mode);
}
public function rewindDate($date,$days,$minutes)
{
$i = 'P'.$days.'D'.'T'.$minutes.'M'; //change S to M for production
$date->getTimestamp();
$di = new DateInterval($i);
$date->sub($di);
return $date;
}
public function currentDateTime()
{
$date = new DateTime();
$date->getTimestamp();
return $date;
}
public function formatDate($date, $type)
{
if($type == "sqlite")
{
$f = $date->format('Y-m-d H:i:s'); //HH:MM:SS.SSS
}else if ($type == "unix")
{
$f = $date->format('U');
}
return $f;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment