开发者

Eval Date to show just day number

开发者 https://www.devze.com 2023-02-14 16:26 出处:网络
I am using the following code Eval(\"EventDate\", \"{0:d}\") This returns 1/4/2011 I need it to return \"4\" just the day. But if I do this

I am using the following code

Eval("EventDate", "{0:d}")

This returns 1/4/2011

I need it to return "4" just the day. But if I do this

Eval("Ev开发者_如何学运维entDate", "{0: d}")

It returns " 4" note the space, this is causing problems is there anyway to just get the day number without that space.

Thanks


You should be able to do this using Eval("EventDate", "{0:%d}"). The % indicates that this is a custom format string.


Use something like this:

String.Format("{0: d}", Eval("EventDate")).Replace(" ", "")


AFAIK, d here is synonym for a short date pattern (DateTimeFormatInfo.ShortDatePattern - M/d/yyyy for en-US culture).

You could use

Eval("EventDate", "{0: dd}")

which gets you 04 or

((DateTime)Eval("EventDate")).Date

or just

string.Format("{0: d}", Eval("EventDate"))

as proposed above.


Off the top of my head I would try adding a Trim on the end of the Eval statement. Like this:

Eval("EventDate", "{0: d}").Trim()

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号