Concatenate string

Asked

Viewed 94 times

-2

I want to concatenate the current day with the character "0", but I’m not getting.

string diaAtual = DateTime.Now.ToString("d");
string diaFormatado = diaAtual+"0";

I need to do this to insert in a select I’m using. Because in the database the date is in a different format. The day 01 is 10, the day 02 is 20 and so on. So I’m using the following select to pick the smaller dates than today

SELECT COUNT(DISTINCT SALES_ORDER) AS SALES_ORDER, COUNT(DISTINCT DELIVERY) 
AS DELIVERY, COUNT(MATERIAL) AS MATERIAL 
FROM V_CABOS WHERE DT_INI IS NOT NULL AND DT_FIM IS NULL AND PRIORIDADE < 30

Only that in place of the day that means 3 (current day), I want to put the concatenation that in the case would be diaFormated.

  • 1

    What happened to executing that code?

  • The first day has to be 10, the second day has to be 20 and so on. I need to do this to put in a select and take everything that is smaller than the current date, only that the date in the bank is the way I explained above

  • Is it worth reading that post

  • Okay, but was there an error in the code? Explain the "I’m not getting it," please

  • This is the select I’m using: SELECT COUNT(DISTINCT SALES_ORDER) AS SALES_ORDER, COUNT(DISTINCT DELIVERY) AS DELIVERY, COUNT(MATERIAL) AS MATERIAL FROM V_CABOS WHERE DT_INI IS NOT NULL AND DT_FIM IS NULL AND PRIORITY < 30. 30 means day 3. If I run the code with the value 30, it works normally. Only when trying to concatenate the current day with 0 to 30, select only returns 0.

  • Are you sure you want to concatenate right? if you are working with date, could add 10 days... if you want to fill the empty space in a string, could use the PadRight() but it still doesn’t make sense. What exactly you’re doing and what you want with it?

  • What do you mean 30 means 3? 300 would be 30?

  • In the database the day 01 is as 10, the day 02 as 20, and so on. I want to take whatever is smaller than the current day, which in this case is 30. So so that I don’t keep changing the code every day, I just want to take the current day without zero and add the zero right. Yes 300 would be 30

  • It is not clear why you need to do this, even appearing to be one XY problem. As for the problem in the question, I don’t know much about C#, but I tested your code and realized the values, which makes your question even more confusing.

  • But day 1 is saved as 10 ? And 10 would be 100 ? It seems very strange what you are trying to do. What is the purpose of this transformation ? Why was it stored like that in the bank ?

  • This comes from a used system where I work. It formats the date this way in the bank. Yes day 1 is 10 and day 10 is 100.

Show 6 more comments

1 answer

1

to get the current day already with two houses you must use the command:

string diaAtual = DateTime.Now.ToString("dd");
  • I can’t take the date this way. I have to take the date format from 1 to 31 and not from 01 to 31.

Browser other questions tagged

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