2
I’m writing a function that gets a string with a date (format dd/mm/aaaa
) and it must return a date (in the same format) 4 weeks later.
Example:
Entrada: 07/04/2016
saída: 05/05/2016
I read about it and thought of the following logic:
Read the date and turn the corresponding week into integer, add 4 and do the opposite process.
Follows code:
//entrada 07/04/2016
private string CalcularDataEntrega(string dataEntrada)
{
//regra: Data Geração + 4 Semanas;
DateTime dataGen = DateTime.Parse(dataEntrada);
Calendar cal = new GregorianCalendar();
int semanaInicio = cal.GetWeekOfYear(dataGen); //erro
int semanaFim = semanaInicio + 4;
//retornar data com base na semana
string dataSaida; //o que colocar?
return dataSaida;
}
In this Example from the Microsoft documentation it was not clear what exactly this function GetWeekOfYear
returns (integer, string?).
I don’t know if I understand what you want, but is there any reason to avoid adding 28 days?
– Maniero
dataGen.Adddays(28);
– Rafael Ferreira
. . . really, hadn’t thought of it, it seems incredibly obvious. Thanks anyway
– Guilherme Golfetto