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?
2017-00-06
is not a valid date!– novic
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.
– Mariana
dr
is what ???– novic
What comes in the
dr["data_inicio"]
?– Felipe Avelar
It must be using a Datareader and called the object dr. The dr["start_data"] must contain the date it recovered from the database.
– Sérgio Lopes
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.
– Jéf Bueno
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.
– Mariana
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.
– Mariana