skip to Main Content

This is the text box:
<asp:TextBox ID="BirthDateEdTB" runat="server" MaxLength="50" TextMode="Date" class="form-control" DateFormat="dd/MM/yyyy" DisplayDateFormat="dd/MM/yyyy" required="required"></asp:TextBox>

I have an object of user that has birthdate from type DateTime. I took this date, and I want to show it in the textbox.

I tried looking for ideas but didn’t find anything that works.

2

Answers


  1. Can you try this code?

    CONVERT(DATETIME,dateTimePicker1.Value.ToString("yyyy-MM-dd"),102)

    Login or Signup to reply.
  2. You can set "any" format you want for the text box.

    However, WHEN you attempt to fill it out, you STILL want to use a iso date format.

    so, say this date:

            DateTime dtBirth = new DateTime(2000, 1, 1);
    
            BirthDateEdTB.Text = dtBirth.ToString("yyyy-MM-dd");
    

    So, while you have a forced/custom format of dd/MM/yyyy, you STILL are to feed the control a iso date format (like yyyy-MM-dd).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search