Eval Date to show just day number
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()
精彩评论