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:


You should just be able to do:


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

  • 4
    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. Jul 15 '15 at 16:47
  • 1
    Fair comment, I didn't know that :) Jul 15 '15 at 16:51
  • 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
    Jul 15 '15 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.