Formatting Date, Ect. when using Eval("FieldName")

Here is my code:

<asp:Repeater ID="Repeater1" runat="server">
   <ItemTemplate>
           <ul>
                <li class="postdate"><%#Eval("DatePosted"))%> </li>
                <li class="posttitle"><%#Eval("BlogEntryTitle")%> </li>
                <li class="postcontent"><%#Eval("BlogEntry")%> </li>
                <li class="postedby">posted by <%#Eval("PosterId")%>  @ <%#Eval("DatePosted")%> </li>
           </ul>
   </ItemTemplate>  
</asp:Repeater>

Repeater is databound via SP in code behind.

How do I format the dates here?  

First I want just the date in the format mm/dd/yyy
Secondly I want just the time the from the DatePosted EX : 9:46 AM

any ideas?

Thanks,
Max
LVL 2
alivemediaAsked:
Who is Participating?
 
pauljk1619Commented:
<li class="postdate"><%#Eval("DatePosted", "{0:MM/dd/yy}")%> </li>
<li class="postdate"><%#Eval("DatePosted", "{0:hh:mm tt}")%> </li>
0
 
pauljk1619Commented:
By the way, if this doesn't work, you may have to remove the DataSourceID from your Repeater, so you can use an DataBinder.Eval which contains the arguements for formatting thte string.
0
 
alivemediaAuthor Commented:
perfect, thanks!
0
 
pauljk1619Commented:
If you are using as sqldatasource you can format the bound columns....

http://msdn2.microsoft.com/en-us/library/h73k0a97.aspx

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.