Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-04-21 15:40:24

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

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

#2 2011-04-21 16:00:49

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

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

Online

#3 2011-04-21 18:35:34

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

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

Board footer

Powered by FluxBB