asp.net - using a substring on a C# aspx page -
i'm trying use substring in order specific part of date on aspx masterpage. reason need has template downloaded , css behind it. code i've got:
<span><%= datetime.today.tostring("m").substring(3), ((int)(datetime.today.tostring("m").length) - 2) %></span>
i need pick apart current month first 3 characters in first span , rest of in second span. reason need subtract 2 because adds day of month afterwards.
thank in advance help.
first should use proper format string.
this give month abbreviation (jan, feb, mar, etc)
<%= datetime.today.tostring("mmm") %>
and give full month name
<%= datetime.today.tostring("mmmm") %>
then can substrings on these instead , not worry parsing off day.
something like:
// can create variable here, in code behind, or use repeated // call instead of assigning variable. <% var month = datetime.today.tostring("mmmm"); %> <%= datetime.today.tostring("mmm") %> <%= month.substring(3, month.length - 3) %>
"mmm" should never return more 3 characters (in en-us @ least), replace length of "mmm" call if don't want hard-code 3.
see msdn custom date , time formatting article.
Comments
Post a Comment