Return to Snippet

Revision: 3582
at August 16, 2007 07:28 by nicolaspar


Initial Code
function hours12ToTimestamp24( $hora ){
	#Saco solo hora y min en un array
	$horaArray = explode(":", $hora);
	if( sizeof( $horaArray ) < 2 ) return 0;
	#Si tiene pm en el string le sumo 12 hs al mod de la hora sobre 12.
	$extra = strstr(strtolower($hora), 'pm') || strstr(strtolower($hora), 'p.m')? 12 : 0;
	return mktime(($horaArray[0]%12)+$extra, $horaArray[1], 0, 1, 1, 1970 );
}

Initial URL


Initial Description
Convert 12hs format to 24hs format. In example: 10:00:00 a.m. return timestamp for 22:00. Or use: strtotime('1970-01-01 '.$hora);

Initial Title
PHP - 12hs to 24hs

Initial Tags
date, convert

Initial Language
PHP