Easier Dates in PHP

So, much of the work I do involves web apps that use MySQL behind them, and more often than not, I’ve got to deal with dates and date math. PHP has its handy mkTime() function that will return Unix time given a funky order of time chunks (hh, mm, ss, mo, dy, yr). But I could rarely ever remember that particular order, and I always hated trying to parse out my MySQL date (YYYY-MM-DD) into the necessary pieces.

Alas, makeTime() was born:

function makeTime($date) {
	// takes YYYY-MM-DD HH:MM:SS, or some combination thereof and returns mktime
	$length = strlen($date);
	
	$isdate = false;
	$istime = false;
	
	$sArray = explode(" ", $date);
	if (sizeof($sArray) > 1) {
		// explode found a " ", and we now have an array w/ length > 1
		$dateString = $sArray[0];
		$timeString = $sArray[1];		
	} else {
		// explode didn't find a " ", and we have an array w/ length == 1
		// check to see if it's a date or a time value
		if (strstr($sArray[0], "-")) {
			$dateString = $sArray[0];
		} else {
			$timeString = $sArray[0];
		}
	}
	
	if (($dateString) && (sizeof($dateString > 0))) {
		// we have a date string, parse it out
		$dArray = explode("-", $dateString);
		$yr = $dArray[0];
		$mo = $dArray[1];
		$dy = $dArray[2];
	}
	
	if (($timeString) && (sizeof($timeString > 0))) {
		// we have a time string, parse it out		
		$tArray = explode(":", $timeString);
		$hh = $tArray[0];
		$mm = $tArray[1];
		$ss = $tArray[2];
	}
	
	$hh = ($hh) ? $hh : "00";
	$mm = ($mm) ? $mm : "00";
	$ss = ($ss) ? $ss : "00";
	
	$yr = ($yr) ? $yr : date("Y");
	$mo = ($mo) ? $mo : date("m");
	$dy = ($dy) ? $dy : date("d");
	
	return mktime($hh, $mm, $ss, $mo, $dy, $yr);

}

Enjoy!