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

Posted on 2006-04-27
Last Modified: 2007-11-27
Here is my code:

<asp:Repeater ID="Repeater1" runat="server">
                <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>

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?

Question by:alivemedia
    LVL 7

    Accepted Solution

    <li class="postdate"><%#Eval("DatePosted", "{0:MM/dd/yy}")%> </li>
    <li class="postdate"><%#Eval("DatePosted", "{0:hh:mm tt}")%> </li>
    LVL 7

    Expert Comment

    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.
    LVL 2

    Author Comment

    perfect, thanks!
    LVL 7

    Expert Comment

    If you are using as sqldatasource you can format the bound columns....


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now