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

Validate phone number...

Chek if a phone numbers is valid, according to its syntax (should be: "+390523599314"). True if it's valid, False otherwise function is_valid_phone( $phone ) { if ( $phone[0] != "+" ) { ...

Delete or Remove all files and folders in a directory‎...

If you want to delete everything from folder (including subfolders) use this function. function removeDir( $dir ) { if ( is_dir( $dir ) ) { $objects = scandir( $dir ); foreach ( $o...

Detect leap year...

Detect leap year for gregorian and shamsi date. function gLeapYear($year) { if (($year % 4 == 0) and (($year % 100 != 0) or ($year % 400 == 0))) return true; else return ...

URL Checker...

This function check if an url is valid or not. function is_valid_url($url) { return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url); }...