Return to Snippet

Revision: 32800
at October 2, 2010 06:29 by roblynch


Updated Code
function dateStringToDatepickerFormat($dateString)
{
	$pattern = array(
		
		//day
		'd',		//day of the month
		'j',		//3 letter name of the day
		'l',		//full name of the day
		'z',		//day of the year
		
		//month
		'F',		//Month name full
		'M',		//Month name short
		'n',		//numeric month no leading zeros
		'm',		//numeric month leading zeros
		
		//year
		'Y', 		//full numeric year
		'y'		//numeric year: 2 digit
	);
	$replace = array(
		'dd','d','DD','o',
		'MM','M','m','mm',
		'yy','y'
	);
	foreach($pattern as &$p)
	{
		$p = '/'.$p.'/';
	}
	return preg_replace($pattern,$replace,$dateString);
}

Revision: 32799
at October 2, 2010 06:26 by roblynch


Initial Code
function dateStringToDatepickerFormat($dateString)
{
	$pattern = array(
		
		//day
		'd',		//day of the month
		'j',		//3 letter name of the day
		'l',		//full name of the day
		'z',		//day of the year
		
		//month
		'F',		//Month name full
		'M',		//Month name short
		'n',		//numeric month no leading zeros
		'm',		//numeric month leading zeros
		
		//year
		'Y', 		//full numeric year
		'y'			//numeric year: 2 digit
	);
	$replace = array(
		'dd','d','DD','o',
		'MM','M','m','mm',
		'yy','y'
	);
	foreach($pattern as &$p)
	{
		$p = '/'.$p.'/';
	}
	return preg_replace($pattern,$replace,$dateString);
}

Initial URL


Initial Description
This is a simple bit of code that allows you to do a write once date format in a PHP style date() format and convert it to be used by datepicker jQuery UI widget.  It returns the converted string.\r\n\r\nNothing fancy here, but a time saver for the future.\r\n\r\nCould use improvement such as error handling for common PHP dateFormat string values that do not have an equivalent UI portion. Potentially make this a two way conversion.  Add more available options.

Initial Title
Convert PHP date() style dateFormat to the equivalent jQuery UI datepicker string

Initial Tags
javascript

Initial Language
PHP