I have this function in JS:
now = new Date;
var dia_atual = now.getDate();
var atual_data = new Date(document.getElementById("<%= txtDataInicio.ClientID %>").value);
var dia_escolha = document.getElementById("<%= txtDiaVencimento.ClientID %>").value;
if ($("#<%=txtTipodePlano.ClientID %>").val() == "MENSAL") {
if (parseInt(dia_escolha) > parseInt(dia_atual))
{
var total_dias = dia_escolha - dia_atual;
var outraData = new Date();
document.getElementById("<%= txtVencimentoC.ClientID %>").value = outraData.setDate(atual_data.getDate() + total_dias);
}
}
This is txtDataHome:
<asp:TextBox ID="txtDataInicio" runat="server" onBlur="limparDataInvalida(this);" class="form-control"></asp:TextBox>
Where txtDataInicio
is filled with the current date, this way "10/16/2017".
I'm trying to make the account, today I want to add total_dias
, but it is not working, because it does not recognize txtDataInicio
as date.
For example: If day of choice is 20
and current date was 16
, 20 - 16 = 4
, where it should increase the 4 days in txtDataInicio
. However of all the ways that I try, it informs error, I do not have much experience with dates in JS
,
I need to add days to the date, but it is not taking the correct format. Thanks.