The specified value "2017-00-06" does not conform to the required format, "yyyy-MM-dd"

Asked

Viewed 244 times

1

I have a field filled with date:

<asp:TextBox ID="txtValidadeIni" runat="server"
   CssClass="form-control" MaxLength="10" type="date" name="date" 
   pattern="[0-9]{2}\/[0-9]{2}\/[0-9]{4}$" min="1970-01-01" max="2100-02-18">
</asp:TextBox>

When the user fills and saves in a date field in sql correctly, it is saved this way : "2017-10-06" But when I try to bring this field from the database to be shown in the form it’s returning me the following error:

The specified value "2017-00-06" does not conform to the required format, "yyyy-MM-dd"

I have tried several types of formatting, but none shows me the data, follows the last way I tried:

txtValidadeIni.Text = Convert
                      .ToDateTime(dr["data_inicio"]).ToString("yyyy-MM-dd");

How can I convert to show in this field type?

  • 5

    2017-00-06 is not a valid date!

  • But in the database it is correct 2017-10-06, it appears so, only that at the time of converting, it appears this way the date 2017-00-06. All forms of conversion I tried to use, does not appear the date in the textbox.

  • dr is what ???

  • What comes in the dr["data_inicio"]?

  • It must be using a Datareader and called the object dr. The dr["start_data"] must contain the date it recovered from the database.

  • My tip is to check all the dates that are saved in the bank, if the error is really at the time of conversion can be sure that the date is getting wrong there.

  • In the database it is saved like this "2017-10-06", only when it appears in the textbox, it does not appear, the configuration is empty dd/mm/yyyy, when I debug, it informs this error that I reported. dr is datareader, q am recovering from database.

  • I noticed that this problem occurs only in Google Chrome, I took the test in Mozila Firefox and it worked, I do not know why this browser does not work, in case someone has any tips, I thank.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.