return month text

runza

Member
i try to use the formula to return the month in a texte format

$date = {agenda___debut};
list($day, $month, $year) = split(':', $date);
// get the month name
echo monthName($month);

function monthName($month_int) {
$month_int = (int)$month_int;
$months = array("","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
return $months[$month_int];}

best regard
philippe
 
Where are you doing this? In a calc element, or a form submission script, or ...

Assuming {agenda___debut} is a standard fabrik date element, try this:

PHP:
return date('l', strtotime('{agenda___debut_raw}'));

That's a lower case L in the date() format string, btw.

-- hugh
 
calc element

hie

i just need with a calc element to return the month of date record in the date element agenda___debut

i don't find the solution with the strtotime fonction

best regard
philippe
 
i replace 'l' by "M" in order to return the month and i obtain the result sep , oct
and it work fine
i ad this formula to obtain the month

switch ($NomMois) {
case "Jan": $NomMois = "Janvier"; break;
case "Feb": $NomMois = "F?vrier"; break;
case "Mar": $NomMois = "Mars"; break;

}
 
Can you look at your actual table data (in phpMyAdmin) and see what values you have in the (for instance) the 'year' field?

I suspect your problem is that those calc elements don't actually have data in the table yet. The result of the calc is only stored in the table row when you save the form for that row. If you add a calc to a table with existing rows, it won't automagically update all the rows in your table with the calc results.

So you may need to do a one-time update of your table, to pre-set the data for the calc'ed fields. So, for instance, to update a field 'debut_month' with the name of the month from the 'debut' DATETIME column, you would run this query one time in phpMyAdmin (or whatever MySQL client you use):

Code:
UPDATE agenda SET debut_month = MONTHNAME(debut)

NOTE - this will only return the month names in your language if your MySQL's locale is correctly configured, see:

http://dev.mysql.com/doc/refman/5.5/en/locale-support.html

To set the year, you would do ...

Code:
UPDATE agenda SET debut_year = YEAR(debut)

Obviously change the field name(s) to suit.

-- hugh
 
i use this function and it work fine
$NomMois = date("M", strtotime($QuelleDate));
switch ($NomMois) {
case "Jan": $NomMois = "Janvier"; break;
case "Feb": $NomMois = "F?vrier"; break;
case "Mar": $NomMois = "Mars"; break;
case "Apr": $NomMois = "Avril"; break;
case "May": $NomMois = "Mai"; break;
case "Jun": $NomMois = "Juin"; break;
case "Jul": $NomMois = "Juillet"; break;
case "Aug": $NomMois = "Ao?t"; break;
case "Sep": $NomMois = "Septembre"; break;
case "Oct": $NomMois = "Octobre"; break;
case "Nov": $NomMois = "Novembre"; break;
case "Dec": $NomMois = "D?cembre"; break;
}
return $NomMois;
best regard
 
Yup, but that still won't pre-populate any existing rows with the calc result when you add a new calc, or change an existing calc.

BTW, you should be able to set your locale() for dates, and use strftime ...


PHP:
setlocale(LC_TIME, 'fr_FR');
return strftime('%B', strtotime($QuelleDate));
setlocale(LC_TIME, 'en_GB');

You could try just the strftime() without the locale() setting lines, see if your PHP is already configured for your local language. If it returns English months, add the locacale() lines.

Unfortunately, the date() function doesn't respect locale() setting.

If you have to pre-set existing rows with that MySQL query I gave you, MySQL *should* be set for your local language, and should automatically give you the French names. if not, talk to your host about setting up MySQL properly.

-- hugh
 
thanks i look with attention your post , it take time to understand this new knowledge

could you deem fabrik as a framework ?

philippe
 
thanks for your answer , i use your this simple formula to get the date in a correct format

$debut= '{agenda_evenement___debut}';
setlocale(LC_TIME, 'fr_FR');
$date = strftime("%A %d %B %Y",strtotime("$debut"));
setlocale(LC_TIME, 'en_GB');
return $date;

philippe
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top