Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I wrote the following function to convert the current WordPress date format into a format that can be recognized by the jQuery UI Datepicker:

From: http://codex.wordpress.org/Formatting_Date_and_Time

To: http://docs.jquery.com/UI/Datepicker/formatDate

/** 
 * Convert a date format to a jQuery UI DatePicker format  
 * 
 * @param string $dateFormat a date format 
 * @return string 
 */ 
function dateFormatTojQueryUIDatePickerFormat($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); 
} 

Anyone know of any easier/built-in way to accomplish this?

share|improve this question
add comment

1 Answer

as for the document of the datapicker UI , I believe you do not need this function . the document specifies that you can use the following formats :

COOKIE - 'D, dd M yy'
ISO_8601 - 'yy-mm-dd' 

which are ,IMHO, compatible . At any rate , there are many PHP functions that will help you do time - converstion, you should look at some of them here :

http://www.php.net/manual/en/ref.datetime.php

For example :

you could also define that in Jquery directly like this :

Date.firstDayOfWeek = 0;
Date.format = 'yyyy-mm-dd';
$(function()
{
    $('.date-pick').datePicker()
});

If none of these solutions suit you there is also a specific plugin that might help :

http://joncom.be/code/jquery-phpdate/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.