Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 494 Vote(s) - 3.43 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert strtotime() to StrFTime()

#1
I was asked to write a module for our billing system and completed it using all of the functions I am accustomed to. It was tested on an English setup, but I did not take into account (nor was I aware of) the fact the actual system our company uses is French.

The code that 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 unfamiliar with StrFTime and wondering how I can use it to get this code to work for French locale?
Reply

#2
Made an simple and quick example. Hope this helps

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

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

#3
First you should use `setlocale`

setlocale(LC_TIME, "fr_FR");

Second, For compare date as string or int you should still use `strtotime` and not `strftime`. (or you can use always string in format `YYYY-mm-dd`

`strftime` is only for to represent date as string.
If you want store it, or to manipulate it, you should use a standard format and not localized. See [doc][1]

>To avoid potential ambiguity, it's best to use ISO 8601 (YYYY-MM-DD) dates or DateTime::createFromFormat() when possible.

So a possible code

//$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]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through