I'm trying to convert this VB block to C#.
Public Function AddWorkingDays(ByVal DateIn As DateTime, _
ByVal ShiftDate As Integer) As DateTime
Dim b As Integer
Dim datDate As DateTime = DateIn ' Adds the [ShiftDate] number of working days to DateIn'
For b = 1 To ShiftDate
datDate = datDate.AddDays(1)
' Loop around until we get the need non-weekend day'
If Weekday(datDate) = 7 Then
datDate = datDate.AddDays(2)
End If
Next
Return datDate
End Function
So far I've got
public DateTime AddWorkingDays(DateTime DateIn, int ShiftDate)
{
int b = 0;
DateTime datDate = DateIn;
// Adds the [ShiftDate] number of working days to DateIn
for (b = 1; b <= ShiftDate; b++)
{
datDate = datDate.AddDays(1);
// Loop around until we get the need non-weekend day
if (DateAndTime.Weekday(datDate) == 7)
{
datDate = datDate.AddDays(2);
}
}
return datDate;
}
I know that there doesn't exist in C# DateAndTime I just put it in the if statement to complete the block of code. My real problem is getting the IF statement to work. I am not sure if DateTime.Now.Weekday is the same statement as in the previous VB code.
Just use the DayOfWeek enumeration, e.g.
datDate.DayOfWeek == DayOfWeek.Saturday
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With