Change timestamp to custom format

Use this function for change timestamp to custom format.

function changeTimeStamp( $date, $dateOutput )
{
   $year = substr( $date, 0, 4 );
   $month = substr( $date, 5, 2 );
   $day = substr( $date, 8, 2 );
   $hour = substr( $date, 11, 2 );
   $minute = substr( $date, 14, 2 );
   $sec = substr( $date, 17, 2 );
 
   $dateOutput = ereg_replace( "YYYY", $year, $dateOutput );
   $dateOutput = ereg_replace( "MM", $month, $dateOutput );
   $dateOutput = ereg_replace( "DD", $day, $dateOutput );
   $dateOutput = ereg_replace( "hh", $hour, $dateOutput );
   $dateOutput = ereg_replace( "mm", $minute, $dateOutput );
   $dateOutput = ereg_replace( "ss", $sec, $dateOutput );
 
   return $dateOutput;
}
 
echo changeTimeStamp( '2013-12-13 12:50:30', 'ss' ); //out = 30
echo changeTimeStamp( '2013-12-13 12:50:30', 'DD.MM.YYYY' ); //out = 13.12.2013
echo changeTimeStamp( '2013-12-13 12:50:30', 'hh.mm.ss' ); //out = 12:50:30

Tags

No tag here.

Recommended pages

Better parse_str in php...

parse_str() is fine for simple stuff but it's not the same as PHP's built way of creating the $_GET magic variable. Why?!?......

File size calculator...

File size calculator function return file size format into kb, mb or gb. function file_size($size, $out = 'kb', $precision = 2) { switch ($out) { case 'kb': return round($...

alphaID - Translates a number to a short alhanumeric version...

Translates a number to a short alhanumeric version. e.g.: 9007199254740989 --> PpQXn7COf In most cases this is better than totally random ID generators because this can easily avoid duplicate ID's. Fo...

Get all subsets of array...

If you have a list of items (for example)......