0

I'm looking for a solution to write a day as string from an Integer.

I found this to have the current day as a string.

{{ 'now' | localizeddate("none", "none", null, null, "EEEE") | capitalize }}

Result => Monday

But I would like to replace 'now' by an integer.

1 for Monday 2 for Tuesday 3 for W...

Johnny
  • 2,989
  • 4
  • 17
  • 28

1 Answers1

0

In your Controller PHP :

$day_number = date('N', strtotime('Monday'));

In your TWIG template :

{{ day_number | localizeddate("none", "none", null, null, "EEEE") | capitalize }}
Antoine Subit
  • 9,803
  • 4
  • 36
  • 52
  • Thanks, Yes I already tried this. For example, when I try `{{ 1 | localizeddate("none", "none", null, null, "EEEE") | capitalize }}`it returns Thursday not Monday – Johnny Nov 16 '16 at 15:53
  • 1
    Try `var_dump(date("1"));` if result is "Monday" it means that TWIG need intl extention to be defined (http://twig.sensiolabs.org/doc/extensions/intl.html#the-intl-extension). If result is "Thursday" it means that PHP need intl timezone to be defined in php.ini (http://php.net/manual/fr/datetime.configuration.php#ini.date.timezone). – Antoine Subit Nov 16 '16 at 16:00