-2

All of you please try to understand {segment_4} is not a variable. its taking 4th value from URL e.g. www.example.com/panel/vals/2015/09 i.e. 09

I am using mktime function in Expression engine but its giving incorrect month name even i have set localization setting from admin panel to india kolkata here is the code :-

<?php echo date('F', mktime(0, 0, 0, {segment_4}, 10));?> 

here segment_4 is month in digit eg. 09 but its showing December it should be September I researched for it every where said that function is correct I have to set anything else in expression engine ?

One more thing when i used this code :-

echo date_default_timezone_get();

then its showing Europe/London even i have changed time zone in EE by india/kolkata

Thanks in advance

Abhay
  • 11
  • 4
  • Try using a dollar in front of the variable name and you dont need the curly brackets either i.e. `$segment_4` – RiggsFolly Sep 30 '15 at 09:41
  • I don't think this question is related to expressionengine. I think it is pure PHP. – Amarnasan Sep 30 '15 at 09:50
  • @RiggsFolly there is no variable and have you ever used expression engine its necessary in EE to use { } symbol – Abhay Sep 30 '15 at 09:51
  • @Amarnasan ok means you are ignoring EE localization setting.. i know its pure php code but its not working in EE thus i want to ask is there any setting for time zone in EE rather than localization setting. – Abhay Sep 30 '15 at 09:52
  • Have you tried to call that `mktime` with `9` instead of `{segment_4}`, just to check if you actually get September? – Amarnasan Sep 30 '15 at 09:58
  • 1
    `09` is different from `9`. It is there silently converted to `0` – fpietka Sep 30 '15 at 10:00
  • @Amarnasan with digit 9 its showing September but with 09 its showing December i am getting 09 in segment_4 – Abhay Sep 30 '15 at 10:03
  • And that proves that it had nothing to do with localization: With a 9 you get September as expected. – Amarnasan Sep 30 '15 at 10:20
  • @Amarnasan but why 09 is coming instead of 9 its a BIG que. right ? – Abhay Sep 30 '15 at 10:23

1 Answers1

1

Ok, you have a '09', which is interpreted as an octal 9, which is an error, (because symbol '9' doesn't exist in octal) and thus it is converted to 0. Which is interpreted by mktime as december. From @fpietka comment.

I'd suggest using

<?php echo date('F', mktime(0, 0, 0, ltrim($segment_4, "0"), 10));?> 
Amarnasan
  • 14,939
  • 5
  • 33
  • 37
  • so know what i have to do because 3 website are working on this code with multi site management lots of template are using this code.. – Abhay Sep 30 '15 at 10:07
  • @Rizier123 you have answer ? – Abhay Sep 30 '15 at 10:14
  • @Abhay `ltrim($number, "0")` – Rizier123 Sep 30 '15 at 10:15
  • Still showing December with (int) or with Abhay's ltrim? – Amarnasan Sep 30 '15 at 10:23
  • Then check with ltrim as Rizier123 suggested. And if that doesn't work, I'm sorry but you'll have to edit the controller that uses this template and do it from there. You have to be sure you're passing a 9, and not a 0. – Amarnasan Sep 30 '15 at 10:39
  • @Amarnasan not works and we can not change the link bec. its created by EE look https://ellislab.com/expressionengine/user-guide/add-ons/channel/archive_month_links.html we have no option to change it – Abhay Sep 30 '15 at 11:07
  • Check this... EE =& get_instance();echo date('F', mktime(0, 0, 0, ltrim($this->EE->uri->segment(4),"0"), 10));?> – Amarnasan Sep 30 '15 at 11:32