Page 1 of 1

[solved] CGCalendar: 3-letter month names

Posted: Tue May 13, 2014 5:41 am
by Cerulean
I'm working on my first project using CGCalendar.

Looking at one of the sample templates I see...

Code: Select all

{assign var=month_number value=$event.event_date_start|date_format:"%m"}
{$month_names[$month_number]}
If I want my event start date formatted with 3-letter months (Jan, Feb, etc), do I have to create my own Smarty array of custom month names and get the name from the array using the month number?

Not a problem if so, just wanting to check that there's not an easier way using date_format or something...

Re: CGCalendar: 3-letter month names

Posted: Tue May 13, 2014 6:39 am
by Cerulean
I guess I can just do...

Code: Select all

{$month_names[$month_number]|truncate:3:""}
I thought that maybe the event start date would be passed as a time stamp that could be formatted to a 3-letter month, but it looks like the Smarty date_format modifier doesn't include a short month format: http://www.smarty.net/docs/en/language. ... format.tpl
It seems "%M" is "minute as a decimal number", which is strange because in the PHP date_format function "M" is "A short textual representation of a month (three letters)".

Re: CGCalendar: 3-letter month names

Posted: Tue May 13, 2014 11:22 am
by Jo Morg
%b - abbreviated month name according to the current locale
In PHP as in Smarty... Check also cms_date_format modifier.

ps: note that this comes from the standard strftime parameters, not the PHP date_format function.

Re: CGCalendar: 3-letter month names

Posted: Wed May 14, 2014 7:41 am
by Cerulean
Right you are, thanks.

{$event.event_date_start|date_format:"%b"} gives a 3-letter month.

Confusing how the PHP strftime and date_format functions use some of the same character codes but for different date formats.