<p>You should just be able to do:</p>

<pre><code>postDate|date('m')
</code></pre>

<p><code>postDate</code> by itself should give you a DateTime object which you can then apply the filter to.</p>

CC BY-SA 3.0
2015-07-15T16:47:21.547Z
You should include that the reason he's getting 12 by using `postDate.month|date('m')` is because PHP is trying to build a date solely on the number seven.
Bryan Redeagle
CC BY-SA 3.0
2015-07-15T16:51:27.447Z
Fair comment, I didn't know that :)
Alec Ritson
CC BY-SA 3.0
2015-07-15T17:21:11.593Z
KAPOW! That did it -- and of course trying to parse the 'm' from something already extracting the month is going to give me bad results. I just changed the URI format and it's just what I needed. Thanks.
Neal Magee
CC BY-SA 3.0
2015-07-15T16:42:11.723Z
2015-07-15T16:42:11.723Z
Alec Ritson
<p>We are migrating our site into Craft, which is by and far easy and pleasant. But I'm trying to match our old CMS's permalink structure, which used 2-character months in the URI.</p>

<p>When defining the structure to contain our old content, I'm unable to format the <strong>postDate.month</strong> as I'd like. I thought the Twig below would work, but it's giving me the wrong digit for the month (or example it should be '07' but consistently gives me '12'):</p>

<pre><code>{postDate.year}/{postDate.month|date('m') }/{slug}
</code></pre>

<p>I'm sure this is pretty simple, but I can't pin down the syntax. Could someone please give me a hand?</p>

<p>I need a URI like this:</p>

<pre><code>2015/07/here-is-my-slug
</code></pre>

<postdate><craft-pro>
Formatting Slug {postDate.month} to 2 characters
# Formatting Slug {postDate.month} to 2 characters

(Asked by: username_0 on 2015-07-15)

We are migrating our site into Craft, which is by and far easy and pleasant. But I'm trying to match our old CMS's permalink structure, which used 2-character months in the URI.
When defining the structure to contain our old content, I'm unable to format the postDate.month as I'd like. I thought the Twig below would work, but it's giving me the wrong digit for the month (or example it should be '07' but consistently gives me '12'):
{postDate.year}/{postDate.month|date('m') }/{slug}

I'm sure this is pretty simple, but I can't pin down the syntax. Could someone please give me a hand?
I need a URI like this:
2015/07/here-is-my-slug

**Tags:** postdate, craft-pro


---

## 1 answers

### Answer by username_1 on 2015-07-15. Score: 5 | Accepted answer

You should just be able to do:
postDate|date('m')

postDate by itself should give you a DateTime object which you can then apply the filter to.

> **Comments:**
> **username_2**: You should include that the reason he's getting 12 by using `postDate.month|date('m')` is because PHP is trying to build a date solely on the number seven.  
> **username_1**: Fair comment, I didn't know that :)  
> **username_0**: KAPOW! That did it -- and of course trying to parse the 'm' from something already extracting the month is going to give me bad results. I just changed the URI format and it's just what I needed. Thanks.  

---

