Newbie Question: Formatting a date item in a repeater?

Discussion in 'ASP .Net' started by DC, May 16, 2005.

  1. DC

    DC Guest

    As part of a access based page writtenin c#

    <td> <%# DataBinder.Eval(Container.DataItem, "SeminarDate") %> </td>

    renders the Seminardate as things like "16/05/2005 00:00:00", etc.

    Is there an easy way of making the "SeminarDate" item only diplay the
    date and leave out the time which is set to 00:00:00 in the database Im
    getting the information from anyway?

    Thanks in advance,

    --
    _______________________________________________

    DC

    "You can not reason a man out of a position he did not reach through reason"

    "Don't use a big word where a diminutive one will suffice."

    "A man with a watch knows what time it is. A man with two watches is
    never sure." Segal's Law
     
    DC, May 16, 2005
    #1
    1. Advertising

  2. DC

    Scott Allen Guest

    Yes, there is an version of Eval that accepts a third parameter - a
    format parameter. i.e:

    <%# DataBinder.Eval(Container.DataItem, "SeminarDate", "{0:d}")%>

    For the format specifier you can pick from standard [1] or custom [2]
    format specifiers.

    [1]
    http://msdn.microsoft.com/library/d...e/html/cpconstandarddatetimeformatstrings.asp

    [2]
    http://msdn.microsoft.com/library/d...ide/html/cpconcustomdatetimeformatstrings.asp


    HTH,

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On Mon, 16 May 2005 15:16:22 +0100, DC <> wrote:

    >As part of a access based page writtenin c#
    >
    ><td> <%# DataBinder.Eval(Container.DataItem, "SeminarDate") %> </td>
    >
    >renders the Seminardate as things like "16/05/2005 00:00:00", etc.
    >
    >Is there an easy way of making the "SeminarDate" item only diplay the
    >date and leave out the time which is set to 00:00:00 in the database Im
    >getting the information from anyway?
    >
    >Thanks in advance,
     
    Scott Allen, May 16, 2005
    #2
    1. Advertising

  3. DC

    Karl Seguin Guest

    DataBinder.Eval accepts a 3rd parameter which isthe format.

    <%# DataBinder.Eval(Container.DataItem, "Price", "{0:dd/MM/yyyy}") %>

    http://msdn.microsoft.com/library/d...GlobalizationDateTimeFormatInfoClassTopic.asp

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
    "DC" <> wrote in message
    news:d6a9sv$72s$...
    > As part of a access based page writtenin c#
    >
    > <td> <%# DataBinder.Eval(Container.DataItem, "SeminarDate") %> </td>
    >
    > renders the Seminardate as things like "16/05/2005 00:00:00", etc.
    >
    > Is there an easy way of making the "SeminarDate" item only diplay the date
    > and leave out the time which is set to 00:00:00 in the database Im
    > getting the information from anyway?
    >
    > Thanks in advance,
    >
    > --
    > _______________________________________________
    >
    > DC
    >
    > "You can not reason a man out of a position he did not reach through
    > reason"
    >
    > "Don't use a big word where a diminutive one will suffice."
    >
    > "A man with a watch knows what time it is. A man with two watches is never
    > sure." Segal's Law
    >
     
    Karl Seguin, May 16, 2005
    #3
  4. Try:

    <%# ((DateTime)Container.DataItem).ToShortDateString() %>

    Should do the trick.

    "DC" wrote:

    > As part of a access based page writtenin c#
    >
    > <td> <%# DataBinder.Eval(Container.DataItem, "SeminarDate") %> </td>
    >
    > renders the Seminardate as things like "16/05/2005 00:00:00", etc.
    >
    > Is there an easy way of making the "SeminarDate" item only diplay the
    > date and leave out the time which is set to 00:00:00 in the database Im
    > getting the information from anyway?
    >
    > Thanks in advance,
    >
    > --
    > _______________________________________________
    >
    > DC
    >
    > "You can not reason a man out of a position he did not reach through reason"
    >
    > "Don't use a big word where a diminutive one will suffice."
    >
    > "A man with a watch knows what time it is. A man with two watches is
    > never sure." Segal's Law
    >
    >
     
    =?Utf-8?B?RGF2aWQgVGFsYm90?=, May 16, 2005
    #4
  5. DC

    DC Guest

    Thanks that worked like a dream.

    Luck,

    Scott Allen wrote:

    > Yes, there is an version of Eval that accepts a third parameter - a
    > format parameter. i.e:
    >
    > <%# DataBinder.Eval(Container.DataItem, "SeminarDate", "{0:d}")%>


    --
    _______________________________________________

    DC

    "You can not reason a man out of a position he did not reach through reason"

    "Don't use a big word where a diminutive one will suffice."

    "A man with a watch knows what time it is. A man with two watches is
    never sure." Segal's Law
     
    DC, May 16, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RP
    Replies:
    4
    Views:
    549
  2. Matt
    Replies:
    1
    Views:
    608
    Matthew Speed
    Nov 8, 2003
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,278
    Michael Borgwardt
    May 30, 2004
  4. Matt
    Replies:
    2
    Views:
    519
    Pete Becker
    Nov 8, 2003
  5. Matt
    Replies:
    3
    Views:
    724
    Richard Heathfield
    Nov 8, 2003
Loading...

Share This Page