Date variable in B-A-B

Home Forums Scripts GirlsWhoGeek Scripts Date variable in B-A-B

Tagged: 

This topic contains 3 replies, has 2 voices, and was last updated by  amphigory 2 years, 8 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #13937

    Luka
    Participant

    Is it possible to change $date content (to be exact, I want to translate it)

    For example:

    $date = date("l F d Y", $row['timestamp']);

    Can I change each of the four values of this date (actually I would only need to change l and F) and make a new $date variable with new l and F values?

    #14798

    amphigory
    Participant

    You can use PHP’s strtr or str_replace functions:

    $date = strtr($date, array(
    'Monday' => 'lundi',
    'Tuesday' => 'mardi',
    'Wednesday' => 'mercredi',
    'Thursday' => 'jeudi',
    'Friday' => 'vendredi',
    'Saturday' => 'samedi',
    'Sunday' => 'dimanche'
    ));

    Of course, the same applies to translating months.

    You can also use setlocale and strftime to format a date without translating:

    setlocale(LC_TIME, 'french');
    $date = strftime('%A %B %d %Y', $row);

    #14799

    Luka
    Participant

    Thank you :)

    Although setlocale seems like an easier solution, it didn’t work for me, but strtr works perfectly :D

    #14800

    amphigory
    Participant

    I probably should have mentioned there are stipulations with setlocale :P It relies entirely on the operating system and the locale you try to set needs to be installed on the system. There are also circumstances where the locale is named differently than you might expect. “french” could be “fr” or “French_France.1252″ or quite a few other possibilities. It’s often difficult getting it to work on a shared server.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.