Date field counting 7 days after the current date in C # [duplicate]

3

I have a field in my application I call txt_dataemissão in case and the current date, and I have another field txt_deadline that I need to show me in that capo the date counted with 7 days after the date of issue, and disregard the end Is it possible to do code in C #, if so how can I do this?

    
asked by anonymous 26.09.2017 / 18:39

1 answer

2

Just compare if the day is Saturday or Sunday until seven days are added

 DateTime d1 = Convert.ToDateTime(txt_dataemissão.Text);   
 int dias = 0;
 while (dias < 7)
 {
    d1 = d1.AddDays(1);
    if (diaUtil(d1)) dias++;
 }
 txt_deadline.Text = d1.ToString();

the diaUtil () method will tell if the day is Saturday or Sunday

    private bool diaUtil(DateTime x)
    {
        if (x.DayOfWeek == DayOfWeek.Sunday || x.DayOfWeek == DayOfWeek.Saturday)
            return false;
        else
            return true;
    }
    
26.09.2017 / 18:47