Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Convert Numeric Month Variable to Text
I am still working on my archives idea and I have a situation where I have a variable m which contains the current date in form [01,02,03…]. I want to be able to output the actual month name instead [January,February,March…].
Now, of course, I could just use a dozen txp:if variable structures. but I was wondering if someone could suggest a better (more efficient/compact) way?
Thanks.
Offline
Re: Convert Numeric Month Variable to Text
Maybe something like this?
<txp:php>$month_num = variable(array("name" => "m")); echo date('F', mktime(0, 0, 0, $month_num));</txp:php>
TXP Builders – finely-crafted code, design and txp
Offline
Re: Convert Numeric Month Variable to Text
I wanted to use it twice on the page – once in the title and once displayed on the page so I modified it slightly with some help from Set textpattern variable in php…
<txp:php>global $variable; $month_num = variable(array("name" => "m")); $variable['monthtitle'] = date('F', mktime(0, 0, 0, $month_num));</txp:php>
and now <txp:variable name=“monthtitle” /> is set.
Thanks. It is so great to be able to ask a question when I get stuck on something like this and not have to spend hours looking for an answer.
Offline