• I try to change the language of the date displayed in an plugin. My search on this issue suggested the use of the WP function mysql2date(). But no matter how hard I try, it always returns the 30. november as the current date. Here is the code:

    $date = mysql2date('j. F', get_option('simple_date'));
    echo $date;

    Any ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter object81

    (@object81)

    Found a little workaround, since the mysql2date() function doesn’t seem to work. Here is my solution of displaying the date localized in modules like SimpleLife, Profilactic or ComplexLife (these modules are basically the same):

    $str = $item->get_date(get_option('simple_date'));
    
    				if (($timestamp = strtotime($str)) === false) {
    					echo "ERROR: The string ($str) is bogus";
    				} else {
    
    					echo '<li class="date">' . strftime("%A, %e %B", $timestamp) . '</li>' . "\r\n";
    				}
    Thread Starter object81

    (@object81)

    A additional tweak to show special characters within the date string I had to use the htmlentities() function.

    // Since they're different, let's replace the old stored date with the new one
    	$stored_date = $item_date;
     	// Display it on the page
    
    		$str = $item->get_date(get_option('simple_date'));
    
    		if (($timestamp = strtotime($str)) === false) {
    		echo "ERROR: The string ($str) is bogus";
    		} else {
    
    		echo '<li class="date">' . htmlentities(strftime("%A, %e %B", $timestamp)) . '</li>' . "\r\n";
    
    		}

    You have to convert the date to the format 'Y-m-d H:i:s' before you can use mysql2date().

    For example:
    $localized_date = mysql2date($date_format, date('Y-m-d H:i:s',get_option('simple_date'));

    This single string does this:

    1. Converts get_option('simple_date') to the format 'Y-m-d H:i:s'; 1221064200 becomes 2008-9-10 11:30:00
    2. mysql2date() translates the string into the current localization using the $date_format variable; 2008-9-10 11:30:00 becomes 10. септембар 2008. 23:30 if the locale is Serbian and the $date_format = 'j. F Y. G:i';

    If the blog date is September 10, 2008 10:41 PM in English, $localized_date will return as 10. септембар 2008. 22:41 in Serbian if I set the $date_format variable as j. F Y. G:i.

    I hope this helps.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘mysql2date() doesn’t work!! Right??’ is closed to new replies.