Remove "/" from a Datetime.Toshortdatestring();

Asked

Viewed 895 times

6

I am implementing a program using C# with . net 3.5

I have the following code:

StringBuilder sb = new StringBuilder();
sb.Append(caminhoSalvarCobranca);
sb.Append(@"\Boleto ");
sb.Append(boleto.Sacado.Nome);
sb.Append(boleto.Boleto.DataVencimento.ToShortDateString);

The "boleto.Boleto.DataVencimento.ToShortDateString" returns a string in the date format "dd/mm/yyyy". It would have some function to remove the bars ("/") and leave only the date (ddmmayya)?

2 answers

6


You can do it as follows:

sb.Append(boleto.Boleto.DataVencimento.ToString("ddMMaaaa");

In this way, the ToString("...") format the date in the desired format and avoid manipulating strings already created.

Note: For more formatting options for DateTime consult this page.

  • I would like to be able to give you an extra positive vote for the link at the end of the reply.

  • @Renan thank you, that page and the page for T-SQL are really handy.

3

You might be doing too:

sb.Append(boleto.Boleto.DataVencimento.ToShortDateString().Replace("/","")); // ddMMyyyy
  • That’s a trick. You’re intentionally generating a string with a format you don’t want, to set it up right away. See the Omni response.

  • @Renan Good, the OP asked how to do this using the ToShortDateString, the answer of the Omni clear is better, I just answered the strict of what was asked.

Browser other questions tagged

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