Return to Snippet

Revision: 38902
at January 10, 2011 07:06 by JonnySnip3r


Initial Code
<?php

function scheduleGameForNextWeek($date)
{
	$day = substr($date,5,-9);
	$month = substr($date,-8,3);
	$year = substr($date, -4);
	
	$month = strtolower($month);
	
	switch($month)
	{
		case "jan":
			$month = "01";
			break;
		case "feb":
			$month = "02";
			break;
		case "mar":
			$month = "03";
			break;
		case "apr":
			$month = "04";
			break;
		case "may":
			$month = "05";
			break;
		case "jun":
			$month = "06";
			break;
		case "jul":
			$month = "07";
			break;
		case "aug":
			$month = "08";
			break;
		case "sep":
			$month = "09";
			break;
		case "oct":
			$month = "10";
			break;
		case "nov":
			$month = "11";
			break;
		case "dec":
			$month = "12";
			break;
		default:
			$month = "00";
			break;
	}
	
	return $newDate = date('F jS Y', mktime(0,0,0,$month,$day+7,$year));
}

$date = "Sun, 9 Jan 2011";

echo $newDate = scheduleGameForNextWeek($date);

?>

Initial URL

                                

Initial Description
This takes a date like so: Sat, 08 Jan 2011 from a database and allows you to use it in your code. For example if you wanted to work out a week from Sat, 08 Jan 2011 it can be done with ease. I created this for a project i am currently working on. There maybe an easier way to deal with this problem but its works so enjoy!

Initial Title
Convert Pretty Dates with PHP

Initial Tags
php, date, function

Initial Language
PHP