Echoing dates on french site?

4 posts by 2 authors in: Forums > CMS Builder
Last Post: September 19, 2013   (RSS)

I have a multilingual site (english and french) and I need to display the dates in preferred format on the french site. Any guidance on how I can do this? 

Currently the months dates are written out (January, February, etc.) and I think the client prefers it that way. Is there a way to output the french translations of the months instead?

By Jason - September 19, 2013

Hi,

Sure, the easiest way to do this is to set up an array of English to French Months.  You can then put the date together one part at a time like this:

$englishToFrenchMonths = array(
    'January'   => 'Janvier',
    'February'  => 'Fevrier',
    'March'     => 'Mars',
    'April'     => 'Avril',
    'May'       => 'Mai',
    'June'      => 'Juin',
    'July'      => 'Juillet',
    'August'    => 'Aout',
    'September' => 'Septembre',
    'October'   => 'Octobre',
    'November'  => 'Novembre',
    'December'  => 'Decembre',
  );
  
  $month = $englishToFrenchMonths[date("F", strtotime($record['date']))];
  $day   = date("d", strtotime($record['date']));
  $year  = date("Y", strtotime($record['date']));
   
  echo "$day/$month/$year";

Hope this helps

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/