Formatting dates?

1,191 views
Skip to first unread message

Brian Vallelunga

unread,
Jan 5, 2012, 8:24:01 PM1/5/12
to dotl...@googlegroups.com
I'm not sure what I'm doing wrong here, but I can't seem to get a DateTime to format properly.

If I do something like:

{{ StartDate }}

I get the default DateTime format. If I do:

{{ StartDate | date "%B" }}

I get: B

According to the docs, I should get the full month. What's wrong with this?

Tim Jones

unread,
Jan 6, 2012, 12:42:52 PM1/6/12
to dotl...@googlegroups.com
Hi Brian,

You're missing a colon before the formatting parameter:

{{ StartDate | date: "%B" }}

Hope that helps,
Tim

Gregory Menvielle

unread,
Feb 4, 2012, 12:18:58 AM2/4/12
to dotliquid
Tim and Brian,
I am running into a similar issue as Brian and could not find another
bit of info on the wiki.
When trying to format the date I would expect StartDate (using Brian's
example) to be set as a DateTime correct?

Thank you...and Thank you Tim for this great port to .Net, really
useful!

Gregory

Tim Jones

unread,
Feb 5, 2012, 10:06:28 PM2/5/12
to dotl...@googlegroups.com
Hi Gregory,

Actually the Date filter will call ToString() on whatever is passed in, and then pass the result of that to DateTime.TryParse().

So you can use either a DateTime, or a String.

Tim

Gregory Menvielle

unread,
Feb 7, 2012, 12:20:10 AM2/7/12
to dotliquid
Tim,
Sorry to bug you again, I must be missing a simple step. Whether I do:
{{ '2012-3-1' | date:"%B" }} or...
{{ '3/2/2012' | date:"%B" }} or any other combination
I always get the full date displayed rather than the proper
conversion. Would you have any suggestions as to where to look next?

Thank you,
Gregory

On Feb 5, 9:06 pm, Tim Jones <t...@timjones.tw> wrote:
> Hi Gregory,
>
> Actually the Date filter will call ToString() on whatever is passed in, and
> then pass the result of that to DateTime.TryParse().https://github.com/formosatek/dotliquid/blob/master/src/DotLiquid/Sta...

Tim Jones

unread,
Feb 7, 2012, 11:36:24 PM2/7/12
to dotl...@googlegroups.com
Hi Gregory,

I see the problem now. DotLiquid supports two styles of date format strings - .NET, and Ruby. You can toggle between the two using

Liquid.UseRubyDateFormat = [true/false];

You're using a Ruby date format string, but presumably UseRubyDateFormat is set to false.

I've made a note of this on the wiki page, because it's not obvious.

Thanks,
Tim
Message has been deleted

Gregory Menvielle

unread,
Feb 11, 2012, 1:25:05 PM2/11/12
to dotliquid
Thank you Tim.
For those of you keeping track at home and having a similar issue as
mine, an important elements to get it to work that I missed at first:
The format is: {{  '3/2/2012' | Date:"%B" }}   and not {{  '3/2/2012'
| date:"%B" }}   (need an upper case D for Date)

On Feb 7, 10:36 pm, Tim Jones <t...@timjones.tw> wrote:
> Hi Gregory,
>
> I see the problem now. DotLiquid supports two styles of date format strings
> - .NET, and Ruby. You can toggle between the two using
>
> Liquid.UseRubyDateFormat = [true/false];
>
> You're using a Ruby date format string, but presumably UseRubyDateFormat is
> set to false.
>
> I've made a note of this on the wiki page<https://github.com/formosatek/dotliquid/wiki/DotLiquid-for-Designers>,

Tim Jones

unread,
Feb 11, 2012, 11:44:08 PM2/11/12
to dotl...@googlegroups.com
I think this only applies if you have Template.NamingConvention set to CSharpNamingConvention? By default it uses RubyNamingConvention, which would use lower-case filter names.

Mo

unread,
Apr 1, 2014, 10:00:49 PM4/1/14
to dotl...@googlegroups.com
Hello, what if I have a date already in the template, like  {{  {{date_variable}}  | date:"%B" }} , it will not work on it, even if I use like this {{  '{{date_variable}}'  | date:"%B" }}

How can I reference it like this? 

Tim Jones

unread,
Apr 2, 2014, 5:38:54 AM4/2/14
to dotl...@googlegroups.com
Can't you just use this? I'm not sure what you mean by "already in the template".

{{ date_variable | date:"%B" }}


Tim
Reply all
Reply to author
Forward
0 new messages