4
I’m developing a project and I’m having a problem with a date-to-string conversion (I believe that’s it).
I am counting months between a date and another (algorithm obtained in this other question, if you want a little more context).
But what’s going wrong is that I want to display this month count in a Textbox.
static int ajustaMesAno(DateTime d)
    {
        return d.Year * 12 + d.Month;
    }
 DateTime inicio = dtpvigencia.Value;
 DateTime fim = DateTime.Now;
 int mesesDiff = ajustaMesAno(fim) - ajustaMesAno(inicio);
   if (inicio.Day > fim.Day)
      {
          mesesDiff--;
      }
 mesesDiff = int.Parse(txtcontador.Text);
This instruction block is running inside a btncadastrar, I mean, when I click on it I should fill the Textbox txtcontador, but it does not happen. After clicking on the button it displays the error:
Input string was not in a correct format.
If you want to fill the Textbox
txtcontatorsure wouldn’t you dotxtcontator.Text = mesesDiff.ToString()? You’re doing it backwards...– Matheus Ribeiro
yes exactly that, I do not know where I was thinking right now, such a simple business mds, thank you very much, if you want to comment as reply I put as best answer
– Patrick Perdigão
Normal, we often get lost in a few simple things...
– Matheus Ribeiro