Skip to content

Instantly share code, notes, and snippets.

@tripflex
Created March 30, 2015 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tripflex/ccd02279117faaf365f9 to your computer and use it in GitHub Desktop.
Save tripflex/ccd02279117faaf365f9 to your computer and use it in GitHub Desktop.
Convert WordPress date format to jQuery UI DatePicker format
if( ! function_exists( 'wp_date_format_php_to_js') ){
/**
* Convert a date format to a jQuery UI DatePicker format
*
* @param string $dateFormat a date format
*
* @return string
*/
function wp_date_format_php_to_js( $dateFormat ) {
$chars = array(
// Day
'd' => 'dd',
'j' => 'd',
'l' => 'DD',
'D' => 'D',
// Month
'm' => 'mm',
'n' => 'm',
'F' => 'MM',
'M' => 'M',
// Year
'Y' => 'yy',
'y' => 'y',
);
return strtr( (string) $dateFormat, $chars );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment