Convert strtotime () to StrFTime ()

I was asked to write a module for our billing system and complete it using all the functions I'm used to. It was tested in English, but I did not take into account (and did not know) the fact that the actual system used by our company is French.

The code I wrote is ...

$due_date = strtotime($next_due_date);
$today = date('Y-m-d');
$today_date = strtotime($today);

if ($due_date > $today_date) {

However, I am not familiar with StrFTime and wonder how can I use it to make this code work in French?

+5
source share
2 answers

You must use first setlocale

setlocale(LC_TIME, "fr_FR");

Secondly, for the date of comparison as a string or int, you should still use strtotime, not strftime. (or you can always use a string in the formatYYYY-mm-dd

strftime . , , . . doc

, ISO 8601 (YYYY-MM-DD) DateTime:: createFromFormat(), .

,

//$next_due_date must be in a standard format like YYYY-mm-dd (but not only)
$due_date = strtotime($next_due_date);
$today_date = time();

if ($due_date > $today_date) {
    echo strftime("%c",$due_date) . " is in the future";
}
+1

. ,

<?php
        setlocale(LC_ALL, 'fra_fra');

        $today = date('Y-m-d');
        $date_string = utf8_encode(strftime('%d %B %Y', strtotime($today)));
        echo $date_string;
?>
0

All Articles