none
entity framework datetime data type conversion RRS feed

  • Question

  • since entity framework has only a datetime data type, is there a way to convert to a date type either in the edmx or in an eval statement? i would prefer not to modify the generated code.

    i need to truncate the time so that a validator does not choke on the time.

    eg 1/1/1900 00:00:00 AM --> 1/1/1900

    <asp:Label ID="DateOfBirthLabel" runat="server" 
        Text='<%# Eval("DateOfBirth") %>' />

    i am using ef 5 beta.


    • Edited by tony bonn Tuesday, May 15, 2012 3:08 AM
    Tuesday, May 15, 2012 2:05 AM

Answers

  • this code solves the immediate problem of displaying the desired date format but leaves me with my larger problem of  validating a date with a date picker - a problem which  i will post elsewhere.

    '<%# String.Format("{0:M/d/yyyy }", Eval("DateOfBirth")) %>'

    • Marked as answer by tony bonn Tuesday, May 15, 2012 3:23 AM
    Tuesday, May 15, 2012 3:23 AM

All replies

  • this code solves the immediate problem of displaying the desired date format but leaves me with my larger problem of  validating a date with a date picker - a problem which  i will post elsewhere.

    '<%# String.Format("{0:M/d/yyyy }", Eval("DateOfBirth")) %>'

    • Marked as answer by tony bonn Tuesday, May 15, 2012 3:23 AM
    Tuesday, May 15, 2012 3:23 AM
  • Hi tony bonn,

    Welcome to MSDN Forum.

    I'm glad to hear that you have solved the issue, and thanks for your sharing.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, May 16, 2012 6:25 AM
    Moderator