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? 

By Jason - September 19, 2013

Hi,

Yes, you can output dates in any format needed using the PHP date() function.  In this function, you set the format that you want dates to display in.

For example, if you had a field called "date" and wanted to output it in a dd/mm/YYYY format, you can do so like this:

<?php echo date("d/m/Y", strtotime($record['date']));?>

For more information about the different date formats you can use, take a look at the date manual page on php.net:

http://ca3.php.net/manual/en/function.date.php

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/

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/