shayne54 Posted August 2, 2018 Share Posted August 2, 2018 What is the correct way to write this code so that the output date is properly formatted for French? <?php $questiondate = date('F d, Y', strtotime('-1 week')); ?> This code works correctly for English, but I have searched on here for how to do this in French, and none of the threads I found work when I put them in my code. I have looked at the other threads, but those answers didn't work for what I am trying to do here, which is output a date that is 1 week in the past in French. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted August 2, 2018 Share Posted August 2, 2018 Have you read the manual on the date() function? And read up on what those formatting characters are for? So simply re-arrange the format chars to get what you want. Right now you are getting January 01, 1992 out of your date call. What do the French use for a date? Quote Link to comment Share on other sites More sharing options...
shayne54 Posted August 2, 2018 Author Share Posted August 2, 2018 Thanks for your reply. The date in French should be: day name of month year example: 06 juin 2018 I have tried this code: <?php setlocale (LC_TIME, 'fr_FR.utf8','fra'); ?> <?php $questiondate = strftime('%d %B %Y', strtotime('-1 week')); ?> But that outputs the month in English ( 26 July 2018 ) Quote Link to comment Share on other sites More sharing options...
Barand Posted August 2, 2018 Share Posted August 2, 2018 echo date('F d, Y').'<br>'; // Eng setlocale(LC_TIME, 'fr-FR'); echo strftime('%B %d, %Y'); // Fr Quote Link to comment Share on other sites More sharing options...
requinix Posted August 2, 2018 Share Posted August 2, 2018 The locale may be a different string than one of the two you're using - you normally need, like, 4 or 5 to be portable across operating systems. But even if you had/have the right one, it also has to be installed on the system for it to work. IntlDateFormatter would be better. https://3v4l.org/Fguqh Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.